mirror of
https://github.com/python/cpython.git
synced 2025-08-24 02:35:59 +00:00
gh-93453: No longer create an event loop in get_event_loop() (#98440)
asyncio.get_event_loop() now always return either running event loop or the result of get_event_loop_policy().get_event_loop() call. The latter should now raise an RuntimeError if no current event loop was set instead of creating and setting a new event loop. It affects also a number of asyncio functions and constructors which call get_event_loop() implicitly: ensure_future(), shield(), gather(), etc. DeprecationWarning is no longer emitted if there is no running event loop but the current event loop was set. Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
b72014c783
commit
fd38a2f0ec
18 changed files with 114 additions and 251 deletions
|
@ -582,7 +582,7 @@ def as_completed(fs, *, timeout=None):
|
|||
from .queues import Queue # Import here to avoid circular import problem.
|
||||
done = Queue()
|
||||
|
||||
loop = events._get_event_loop()
|
||||
loop = events.get_event_loop()
|
||||
todo = {ensure_future(f, loop=loop) for f in set(fs)}
|
||||
timeout_handle = None
|
||||
|
||||
|
@ -668,7 +668,7 @@ def _ensure_future(coro_or_future, *, loop=None):
|
|||
'is required')
|
||||
|
||||
if loop is None:
|
||||
loop = events._get_event_loop(stacklevel=4)
|
||||
loop = events.get_event_loop()
|
||||
try:
|
||||
return loop.create_task(coro_or_future)
|
||||
except RuntimeError:
|
||||
|
@ -749,7 +749,7 @@ def gather(*coros_or_futures, return_exceptions=False):
|
|||
gather won't cancel any other awaitables.
|
||||
"""
|
||||
if not coros_or_futures:
|
||||
loop = events._get_event_loop()
|
||||
loop = events.get_event_loop()
|
||||
outer = loop.create_future()
|
||||
outer.set_result([])
|
||||
return outer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue