Use context manager

pull/35583/head
Xuan Wang 1 year ago
parent 26bdeee0eb
commit aa0d207e99
  1. 17
      src/python/grpcio/grpc/_cython/_cygrpc/aio/common.pyx.pxi

@ -183,14 +183,15 @@ if PY_MAJOR_VERSION >= 3 and PY_MINOR_VERSION >= 7:
try:
return asyncio.get_running_loop()
except RuntimeError:
# Convert warnings to errors so we can capture them with except
warnings.filterwarnings("error", category=DeprecationWarning, module=__name__)
try:
return asyncio.get_event_loop_policy().get_event_loop()
# Since version 3.12, DeprecationWarning is emitted if there is no
# current event loop.
except DeprecationWarning:
return asyncio.get_event_loop_policy().new_event_loop()
with warnings.catch_warnings():
# Convert DeprecationWarning to errors so we can capture them with except
warnings.simplefilter("error", DeprecationWarning)
try:
return asyncio.get_event_loop_policy().get_event_loop()
# Since version 3.12, DeprecationWarning is emitted if there is no
# current event loop.
except DeprecationWarning:
return asyncio.get_event_loop_policy().new_event_loop()
else:
def get_working_loop():
"""Returns a running event loop."""

Loading…
Cancel
Save