Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeprecationWarning "There is no current event loop" from use of asyncio.get_event_loop #491

Open
mdickinson opened this issue Dec 16, 2021 · 0 comments
Labels
type: refactor Cleanup or refactoring tasks that don't add functionality or fix bugs

Comments

@mdickinson
Copy link
Member

The use of asyncio.get_event_loop causes a DeprecationWarning for Python 3.10, and will become an error in some future version of Python.

Here's the output of the test run on my machine on Python 3.10:

(traits-futures) mdickinson@mirzakhani traits-futures % python -m unittest
/Users/mdickinson/Enthought/Projects/traits-futures/traits_futures/asyncio/event_loop.py:28: DeprecationWarning: There is no current event loop
  self._event_loop = asyncio.get_event_loop()
................ssssssssssssssss............................................................/Users/mdickinson/.venvs/traits-futures/lib/python3.10/site-packages/pyface/base_toolkit.py:285: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
  plugin for plugin in importlib_metadata.entry_points()[entry_point]
../Users/mdickinson/.venvs/traits-futures/lib/python3.10/site-packages/pyface/base_toolkit.py:216: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
  entry_point_group = importlib_metadata.entry_points()[entry_point]
....ss................................................................................................/Users/mdickinson/Enthought/Projects/traits-futures/traits_futures/asyncio/event_loop.py:28: DeprecationWarning: There is no current event loop
  self._event_loop = asyncio.get_event_loop()
../Users/mdickinson/Enthought/Projects/traits-futures/traits_futures/asyncio/event_loop.py:28: DeprecationWarning: There is no current event loop
  self._event_loop = asyncio.get_event_loop()
./Users/mdickinson/Enthought/Projects/traits-futures/traits_futures/asyncio/event_loop.py:28: DeprecationWarning: There is no current event loop
  self._event_loop = asyncio.get_event_loop()
............/Users/mdickinson/Enthought/Projects/traits-futures/traits_futures/asyncio/event_loop.py:28: DeprecationWarning: There is no current event loop
  self._event_loop = asyncio.get_event_loop()
..................../Users/mdickinson/Enthought/Projects/traits-futures/traits_futures/asyncio/event_loop.py:28: DeprecationWarning: There is no current event loop
  self._event_loop = asyncio.get_event_loop()
../Users/mdickinson/Enthought/Projects/traits-futures/traits_futures/asyncio/event_loop.py:28: DeprecationWarning: There is no current event loop
  self._event_loop = asyncio.get_event_loop()
./Users/mdickinson/Enthought/Projects/traits-futures/traits_futures/asyncio/event_loop.py:28: DeprecationWarning: There is no current event loop
  self._event_loop = asyncio.get_event_loop()
..................../Users/mdickinson/Enthought/Projects/traits-futures/traits_futures/asyncio/event_loop.py:28: DeprecationWarning: There is no current event loop
  self._event_loop = asyncio.get_event_loop()
../Users/mdickinson/Enthought/Projects/traits-futures/traits_futures/asyncio/event_loop.py:28: DeprecationWarning: There is no current event loop
  self._event_loop = asyncio.get_event_loop()
./Users/mdickinson/Enthought/Projects/traits-futures/traits_futures/asyncio/event_loop.py:28: DeprecationWarning: There is no current event loop
  self._event_loop = asyncio.get_event_loop()
...........ssssssssssssssss
----------------------------------------------------------------------
Ran 284 tests in 19.763s

OK (skipped=34)

The easiest quick fix is to replace uses of asyncio.get_event_loop with asyncio.new_event_loop. The catch is that that leaves us responsible for clearing up (i.e., explicitly closing) those event loops, to avoid getting ResourceWarning warnings.

See https://bugs.python.org/issue39529 for the rationale for the deprecation, and related discussion.

@mdickinson mdickinson added the type: refactor Cleanup or refactoring tasks that don't add functionality or fix bugs label Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: refactor Cleanup or refactoring tasks that don't add functionality or fix bugs
Projects
None yet
Development

No branches or pull requests

1 participant