◐ Shell
reader mode source ↗
Skip to content

gh-94597: add asyncio.EventLoop#110723

Merged
gvanrossum merged 9 commits into
python:mainfrom
graingert:add-asyncio-event-loop
Oct 12, 2023
Merged

gh-94597: add asyncio.EventLoop#110723
gvanrossum merged 9 commits into
python:mainfrom
graingert:add-asyncio-event-loop

Conversation

@graingert

@graingert graingert commented Oct 11, 2023

Copy link
Copy Markdown
Contributor

@graingert

graingert commented Oct 11, 2023

Copy link
Copy Markdown
Contributor Author

This allows running asyncio coroutines without interacting with the policy system eg:

asyncio.run(main(), loop_factory=asyncio.EventLoop)
# no need to call asyncio.set_event_loop_policy(None) !

this allows code to run without interfering with a policy that has been set in one location especially one that expects asyncio.set_event_loop() to be called after every invocation of asyncio.new_event_loop()

@graingert graingert changed the title GH-94597 add asyncio.EventLoop Oct 11, 2023
@graingert graingert marked this pull request as ready for review October 11, 2023 16:07

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

Do you intend this to be merged before or after the deprecations PR?

…PC8t.rst

Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
@graingert

graingert commented Oct 12, 2023

Copy link
Copy Markdown
Contributor Author

Do you intend this to be merged before or after the deprecations PR?

I don't mind what order the PRs go in - I plan a cleanup PR for the CPython test suite removing redundant calls to set_event_loop_policy(None) once asyncio.EventLoop is available for use in asyncio.run calls

@kumaraditya303 kumaraditya303 self-assigned this Oct 12, 2023

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

Thanks! Merging now.

@gvanrossum gvanrossum merged commit 8c6c14b into python:main Oct 12, 2023
@graingert graingert deleted the add-asyncio-event-loop branch October 12, 2023 14:14
@vstinner

Copy link
Copy Markdown
Member

It is an alias to :class:SelectorEventLoop on Unix and :class:ProactorEventLoop on Windows.

Well. In the early days of tulip/asyncio, there were more choices, and we didn't know how third-party projects will inherit/override these classes. Now I agree that asyncio.EventLoop is the way to go, it's easier to remind, it's more explicit, and it's easy to guess what is it (SelectorEventLoop or ProactorEventLoop).

Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
This is needed to pave the way for deprecating and eventually killing the event loop policy system (which is over-engineered and rarely used).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants