Closed
Description
Deprecate the child watchers system and the policy system in favour of
asyncio.Runner(loop_factory=asyncio.ProactorEventLoop/asyncio.SelectorEventLoop/uvloop.new_event_loop)
that would be deprecating:
asyncio.get_event_loop() # already deprecated unless the loop is running
asyncio.set_event_loop() # asyncio.set_event_loop(None) should probably be exempt
asyncio.get_event_loop_policy()
asyncio.set_event_loop_policy() # asyncio.set_event_loop_policy(None) should probably be exempt
asyncio.set_child_watcher()
asyncio.get_child_watcher() # `_make_subprocess_transport` will instead attempt to use os.open_pidfd and fallback to starting a thread
I'd also like to introduce a new API: asyncio.EventLoop
implemented as:
if sys.platform == "win32":
EventLoop = ProactorEventLoop
else:
EventLoop = SelectorEventLoop
asyncio.new_event_loop()
will issue a DeprecationWarning if the current policy is not the default policy, and then in 3 releases become an alias of asyncio.EventLoop
Originally posted by @graingert in #93896 (comment)
Metadata
Metadata
Assignees
Projects
Status
Done
Milestone
Relationships
Development
No branches or pull requests
Activity
graingert commentedon Jul 6, 2022
Some background to this proposed deprecation:
This is a more comprehensive version of #82772
@serhiy-storchaka proposed deprecating
set_event_loop()
in #93453 (comment)@asvetlov noted that
get_event_loop_policy().get_event_loop()
was not deprecated by oversight in #83710 (comment)gvanrossum commentedon Jul 6, 2022
We are in dire need of more asyncio experts. @1st1 this isn't urgent but would be nice to have your perspective in time to do this in 3.12.
kumaraditya303 commentedon Jul 6, 2022
For 3.12 IMO we should deprecate
MultiLoopWatcher
#82504 and others which have race condition and other issue. Once that's done we may deprecate the entire child watcher system but just removingMultiLoopWatcher
would be a good start.graingert commentedon Jul 7, 2022
@kumaraditya303 #94648
gvanrossum commentedon Oct 6, 2022
We discussed this at the sprint and we agree that there are many things wrong with the child watchers and the policy system.
Deprecating child watchers: @1st1 thinks these should be done per loop (like uvloop does), not globally by the policy. Much more discussion on this topic is already in #82772. Bottom line, we agree to deprecate it, details remain to be seen.
Deprecating policies: Yes please. The policies no longer serve a real purpose. Loops are always per thread, there is no need to have a "current loop" when no loop is currently running. The only thing we still need is a loop factory, so perhaps instead of an API for getting/setting a global "policy", we could have an API for getting/setting a global "loop factory".
I'm fine with the
EventLoop
alias (it ties up a loose end), but I recommend that the API for creating a new event loop (when not using runners) should beasyncio.new_event_loop()
, notasyncio.EventLoop()
.We should totally deprecate
set_event_loop()
(even withNone
argument). At that point we can makeget_event_loop()
an alias forget_running_loop()
(or the other way around -- I prefer callingget_event_loop()
:-).67 remaining items