How do versions after py3.10 implement asyncio.get_event_loop with the same behavior as previous versions

148 views Asked by At

python3.10-asyncio-get_event_loop

Deprecated since version 3.10: Emits a deprecation warning if there is no running event loop. In future Python releases, this function may become an alias of get_running_loop() and will accordingly raise a RuntimeError if there is no running event loop.

The behavior of get_event_loop has changed in version 3.10, now the sanic-jwt library needs to be compatible with later versions of 3.10, and needs to be modified to remove this warning(DeprecationWarning: There is no current event loop)

The place of the warning is the call method under ConfigItem on line 134 sanic_jwt/configuration.py

enter image description here

I tried the method of this article and the test did not pass. It should not match the behavior of the version before 3.10

PR

1

There are 1 answers

0
Paul Cornelius On

If you want to patch the library, you could replace line 134:

if asyncio.get_event_loop().is_running():
    # some code

with:

try:
    asyncio.get_running_loop()
except RuntimeError:
    pass
else:
    # some code

That should work with all versions of Python.