This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Allow to create new Event Loops on Threads
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.10
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Christian Exposito, asvetlov, christian.heimes, iritkatriel, python-dev, yselivanov
Priority: normal Keywords: patch

Created on 2020-05-28 17:54 by Christian Exposito, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 20500 closed python-dev, 2020-05-28 17:56
Messages (4)
msg370257 - (view) Author: Christian Exposito (Christian Exposito) * Date: 2020-05-28 17:54
Right now, Async IO module is not automatically creating a new event loop on threads that are not the main thread (https://github.com/python/cpython/blob/master/Lib/asyncio/events.py#L638), but it should be interesting to do it. For example, WSGI applications handle web requests by spawning a new thread. If we allow Async IO module to create event loops on those threads, we will improve its adoption for developing web applications.
msg370261 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2020-05-28 18:55
The default policy of asyncio deliberately limits automatic creation of event loops to the main thread. You can't just mix asyncio with a threaded web application and expect it to work correctly.

See https://github.com/python/cpython/blob/a487a39dca4c41305928c7dfdbcb0b3aa344683b/Lib/asyncio/events.py#L609-L620

    In this policy, each thread has its own event loop.  However, we
    only automatically create an event loop by default for the main
    thread; other threads by default have no event loop.

    Other policies may have different rules (e.g. a single global
    event loop, or automatically creating an event loop per thread, or
    using some other notion of context to which an event loop is
    associated).
msg393959 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-05-19 17:07
Should this be closed as rejected or is there further discussion?
msg415410 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-03-17 13:16
I suggest closing.
The documentation explicitly describes how asyncio works with threads.
History
Date User Action Args
2022-04-11 14:59:31adminsetgithub: 84988
2022-03-17 13:16:16asvetlovsetstatus: open -> closed
resolution: wont fix
messages: + msg415410

stage: patch review -> resolved
2021-05-19 17:07:22iritkatrielsetnosy: + iritkatriel
messages: + msg393959
2020-05-28 18:55:11christian.heimessetnosy: + christian.heimes
messages: + msg370261
2020-05-28 17:56:26python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request19748
stage: patch review
2020-05-28 17:54:39Christian Expositocreate