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

Commit 5df0cf1

Browse files
feat: add context manager support in client (#93)
- [ ] 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 ff106ef commit 5df0cf1

File tree

32 files changed

+370
-16
lines changed

32 files changed

+370
-16
lines changed

google/cloud/recommendationengine_v1beta1/services/catalog_service/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,12 @@ async def import_catalog_items(
751751
# Done; return the response.
752752
return response
753753

754+
async def __aenter__(self):
755+
return self
756+
757+
async def __aexit__(self, exc_type, exc, tb):
758+
await self.transport.close()
759+
754760

755761
try:
756762
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/recommendationengine_v1beta1/services/catalog_service/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,7 @@ def __init__(
352352
client_cert_source_for_mtls=client_cert_source_func,
353353
quota_project_id=client_options.quota_project_id,
354354
client_info=client_info,
355-
always_use_jwt_access=(
356-
Transport == type(self).get_transport_class("grpc")
357-
or Transport == type(self).get_transport_class("grpc_asyncio")
358-
),
355+
always_use_jwt_access=True,
359356
)
360357

361358
def create_catalog_item(
@@ -879,6 +876,19 @@ def import_catalog_items(
879876
# Done; return the response.
880877
return response
881878

879+
def __enter__(self):
880+
return self
881+
882+
def __exit__(self, type, value, traceback):
883+
"""Releases underlying transport's resources.
884+
885+
.. warning::
886+
ONLY use as a context manager if the transport is NOT shared
887+
with other clients! Exiting the with block will CLOSE the transport
888+
and may cause errors in other clients!
889+
"""
890+
self.transport.close()
891+
882892

883893
try:
884894
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ def _prep_wrapped_messages(self, client_info):
251251
),
252252
}
253253

254+
def close(self):
255+
"""Closes resources associated with the transport.
256+
257+
.. warning::
258+
Only call this method if the transport is NOT shared
259+
with other clients - this may cause errors in other clients!
260+
"""
261+
raise NotImplementedError()
262+
254263
@property
255264
def operations_client(self) -> operations_v1.OperationsClient:
256265
"""Return the client designed to process long-running operations."""

google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,5 +412,8 @@ def import_catalog_items(
412412
)
413413
return self._stubs["import_catalog_items"]
414414

415+
def close(self):
416+
self.grpc_channel.close()
417+
415418

416419
__all__ = ("CatalogServiceGrpcTransport",)

google/cloud/recommendationengine_v1beta1/services/catalog_service/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,5 +427,8 @@ def import_catalog_items(
427427
)
428428
return self._stubs["import_catalog_items"]
429429

430+
def close(self):
431+
return self.grpc_channel.close()
432+
430433

431434
__all__ = ("CatalogServiceGrpcAsyncIOTransport",)

google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ async def delete_prediction_api_key_registration(
445445
request, retry=retry, timeout=timeout, metadata=metadata,
446446
)
447447

448+
async def __aenter__(self):
449+
return self
450+
451+
async def __aexit__(self, exc_type, exc, tb):
452+
await self.transport.close()
453+
448454

449455
try:
450456
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,7 @@ def __init__(
387387
client_cert_source_for_mtls=client_cert_source_func,
388388
quota_project_id=client_options.quota_project_id,
389389
client_info=client_info,
390-
always_use_jwt_access=(
391-
Transport == type(self).get_transport_class("grpc")
392-
or Transport == type(self).get_transport_class("grpc_asyncio")
393-
),
390+
always_use_jwt_access=True,
394391
)
395392

396393
def create_prediction_api_key_registration(
@@ -650,6 +647,19 @@ def delete_prediction_api_key_registration(
650647
request, retry=retry, timeout=timeout, metadata=metadata,
651648
)
652649

650+
def __enter__(self):
651+
return self
652+
653+
def __exit__(self, type, value, traceback):
654+
"""Releases underlying transport's resources.
655+
656+
.. warning::
657+
ONLY use as a context manager if the transport is NOT shared
658+
with other clients! Exiting the with block will CLOSE the transport
659+
and may cause errors in other clients!
660+
"""
661+
self.transport.close()
662+
653663

654664
try:
655665
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ def _prep_wrapped_messages(self, client_info):
204204
),
205205
}
206206

207+
def close(self):
208+
"""Closes resources associated with the transport.
209+
210+
.. warning::
211+
Only call this method if the transport is NOT shared
212+
with other clients - this may cause errors in other clients!
213+
"""
214+
raise NotImplementedError()
215+
207216
@property
208217
def create_prediction_api_key_registration(
209218
self,

google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,5 +330,8 @@ def delete_prediction_api_key_registration(
330330
)
331331
return self._stubs["delete_prediction_api_key_registration"]
332332

333+
def close(self):
334+
self.grpc_channel.close()
335+
333336

334337
__all__ = ("PredictionApiKeyRegistryGrpcTransport",)

google/cloud/recommendationengine_v1beta1/services/prediction_api_key_registry/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,5 +335,8 @@ def delete_prediction_api_key_registration(
335335
)
336336
return self._stubs["delete_prediction_api_key_registration"]
337337

338+
def close(self):
339+
return self.grpc_channel.close()
340+
338341

339342
__all__ = ("PredictionApiKeyRegistryGrpcAsyncIOTransport",)

0 commit comments

Comments
 (0)