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
gh-100160: Deprecate implicit creation of an event loop #100410
base: main
Are you sure you want to change the base?
gh-100160: Deprecate implicit creation of an event loop #100410
Conversation
Partially revert changes made in pythonGH-93453. asyncio.DefaultEventLoopPolicy.get_event_loop() now emits a DeprecationWarning and creates and sets a new event loop instead of raising a RuntimeError if there is no current event loop set.
Doc/library/asyncio-eventloop.rst
Outdated
the result of calling ``get_event_loop_policy().get_event_loop()``. | ||
the result of ``get_event_loop_policy().get_event_loop()`` call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked the original phrasing better, or perhaps this:
the result of the
get_event_loop_policy().get_event_loop()
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One variant was in 3.12, other variant was in 3.12. I think @ambv edited it in one of PRs.
Applied your suggestion.
Doc/library/asyncio-eventloop.rst
Outdated
the current loop was set. | ||
.. deprecated:: 3.12 | ||
Deprecation warning is emitted if there is no current event loop. | ||
In future Python releases it will be an error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
In some future Python release it will become an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
except AttributeError: | ||
pass | ||
else: | ||
while f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment explaining why this loop is needed? (IIUC it's so the warning is attached to a line outside asyncio itself?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dONE.
break | ||
f = f.f_back | ||
stacklevel += 1 | ||
import warnings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see no reason to delay this import, since it's a toplevel import in base_events.py and proactor_events.py -- by the time this code runs those have been imported anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to only import warnings
when it is used, so the code which does not use any deprecated feature will not need to import it. It also save us from forgetting to remove the import when warnings are replaced with errors. I think that we should do this in base_events.py
and proactor_events.py
.
@@ -0,0 +1,3 @@ | |||
Emit a deprecation warning in | |||
:meth:`asyncio.DefaultEventLoopPolicy.get_event_loop` if there is no current | |||
event loop set and a new event loop has been implicitly created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Same textual change as I suggested above.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
…chaka/cpython into asyncio-get_event_loop3-3.12
Partially revert changes made in GH-93453.
asyncio.DefaultEventLoopPolicy.get_event_loop() now emits a DeprecationWarning and creates and sets a new event loop instead of raising a RuntimeError if there is no current event loop set.