Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit 04dd991

Browse files
feat: add context manager support in client (#168)
- [ ] Regenerate this pull request now. chore: fix docstring for first attribute of protos committer: @busunkim96 PiperOrigin-RevId: 401271153 Source-Link: googleapis/googleapis@787f8c9 Source-Link: https://github.com/googleapis/googleapis-gen/commit/81decffe9fc72396a8153e756d1d67a6eecfd620 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
1 parent 48c7627 commit 04dd991

File tree

95 files changed

+1142
-48
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1142
-48
lines changed

google/cloud/talent_v4/services/company_service/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,12 @@ async def list_companies(
615615
# Done; return the response.
616616
return response
617617

618+
async def __aenter__(self):
619+
return self
620+
621+
async def __aexit__(self, exc_type, exc, tb):
622+
await self.transport.close()
623+
618624

619625
try:
620626
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/talent_v4/services/company_service/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,7 @@ def __init__(
363363
client_cert_source_for_mtls=client_cert_source_func,
364364
quota_project_id=client_options.quota_project_id,
365365
client_info=client_info,
366-
always_use_jwt_access=(
367-
Transport == type(self).get_transport_class("grpc")
368-
or Transport == type(self).get_transport_class("grpc_asyncio")
369-
),
366+
always_use_jwt_access=True,
370367
)
371368

372369
def create_company(
@@ -785,6 +782,19 @@ def list_companies(
785782
# Done; return the response.
786783
return response
787784

785+
def __enter__(self):
786+
return self
787+
788+
def __exit__(self, type, value, traceback):
789+
"""Releases underlying transport's resources.
790+
791+
.. warning::
792+
ONLY use as a context manager if the transport is NOT shared
793+
with other clients! Exiting the with block will CLOSE the transport
794+
and may cause errors in other clients!
795+
"""
796+
self.transport.close()
797+
788798

789799
try:
790800
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/talent_v4/services/company_service/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ def _prep_wrapped_messages(self, client_info):
211211
),
212212
}
213213

214+
def close(self):
215+
"""Closes resources associated with the transport.
216+
217+
.. warning::
218+
Only call this method if the transport is NOT shared
219+
with other clients - this may cause errors in other clients!
220+
"""
221+
raise NotImplementedError()
222+
214223
@property
215224
def create_company(
216225
self,

google/cloud/talent_v4/services/company_service/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,5 +363,8 @@ def list_companies(
363363
)
364364
return self._stubs["list_companies"]
365365

366+
def close(self):
367+
self.grpc_channel.close()
368+
366369

367370
__all__ = ("CompanyServiceGrpcTransport",)

google/cloud/talent_v4/services/company_service/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,5 +371,8 @@ def list_companies(
371371
)
372372
return self._stubs["list_companies"]
373373

374+
def close(self):
375+
return self.grpc_channel.close()
376+
374377

375378
__all__ = ("CompanyServiceGrpcAsyncIOTransport",)

google/cloud/talent_v4/services/completion/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ async def complete_query(
215215
# Done; return the response.
216216
return response
217217

218+
async def __aenter__(self):
219+
return self
220+
221+
async def __aexit__(self, exc_type, exc, tb):
222+
await self.transport.close()
223+
218224

219225
try:
220226
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/talent_v4/services/completion/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,7 @@ def __init__(
355355
client_cert_source_for_mtls=client_cert_source_func,
356356
quota_project_id=client_options.quota_project_id,
357357
client_info=client_info,
358-
always_use_jwt_access=(
359-
Transport == type(self).get_transport_class("grpc")
360-
or Transport == type(self).get_transport_class("grpc_asyncio")
361-
),
358+
always_use_jwt_access=True,
362359
)
363360

364361
def complete_query(
@@ -410,6 +407,19 @@ def complete_query(
410407
# Done; return the response.
411408
return response
412409

410+
def __enter__(self):
411+
return self
412+
413+
def __exit__(self, type, value, traceback):
414+
"""Releases underlying transport's resources.
415+
416+
.. warning::
417+
ONLY use as a context manager if the transport is NOT shared
418+
with other clients! Exiting the with block will CLOSE the transport
419+
and may cause errors in other clients!
420+
"""
421+
self.transport.close()
422+
413423

414424
try:
415425
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/talent_v4/services/completion/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ def _prep_wrapped_messages(self, client_info):
172172
),
173173
}
174174

175+
def close(self):
176+
"""Closes resources associated with the transport.
177+
178+
.. warning::
179+
Only call this method if the transport is NOT shared
180+
with other clients - this may cause errors in other clients!
181+
"""
182+
raise NotImplementedError()
183+
175184
@property
176185
def complete_query(
177186
self,

google/cloud/talent_v4/services/completion/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,8 @@ def complete_query(
256256
)
257257
return self._stubs["complete_query"]
258258

259+
def close(self):
260+
self.grpc_channel.close()
261+
259262

260263
__all__ = ("CompletionGrpcTransport",)

google/cloud/talent_v4/services/completion/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,8 @@ def complete_query(
259259
)
260260
return self._stubs["complete_query"]
261261

262+
def close(self):
263+
return self.grpc_channel.close()
264+
262265

263266
__all__ = ("CompletionGrpcAsyncIOTransport",)

0 commit comments

Comments
 (0)