Skip to content

Commit

Permalink
Suppress warning for specifically handled behavior
Browse files Browse the repository at this point in the history
In Python 3.10, there is a deprecation warning raised when calling
get_event_loop when there is no running loop.
  • Loading branch information
cottsay authored and clalancette committed Jun 23, 2023
1 parent 9442773 commit 6fee05d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion osrf_pycommon/process_utils/get_loop_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import os
import threading
import warnings

_thread_local = threading.local()

Expand All @@ -39,7 +40,20 @@ def get_loop_impl(asyncio):
asyncio.set_event_loop(loop)
else:
try:
loop = asyncio.get_event_loop()
# See the note in
# https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_event_loop .
# In short, between Python 3.10.0 and 3.10.8, this unconditionally
# raises a DeprecationWarning. But after 3.10.8, it only raises a
# the warning if there is no current loop set in the policy.
# Since we are setting a loop in the policy, this warning is spurious,
# and will go away once we get away from Python 3.10.6 (verified
# with Python 3.11.3).
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore',
'There is no current event loop',
DeprecationWarning)
loop = asyncio.get_event_loop()
except (RuntimeError, AssertionError):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
Expand Down

0 comments on commit 6fee05d

Please sign in to comment.