New submission from Ben Darnell <ben.darn...@gmail.com>:

On Windows there are two event loop implementions with different interfaces: 
The proactor event loop is missing the file descriptor family of methods 
(add_reader()), while the selector event loop has other limitations including 
missing support for pipes and subprocesses and generally lower scalability. 
(The default has changed from selector to proactor in Python 3.8).

If an application requires the selector event loop, it can set the global event 
loop policy when it starts up. But what if a library requires the selector 
event loop? It wouldn't be appropriate for a library to set the event loop 
policy. The best I can do is document that "This library requires an event loop 
which supports the add_reader() method; to use this library on Windows 
(directly or indirectly) you must install the WindowsSelectorEventLoopPolicy."  

This places a burden on application developers that target Windows to examine 
all their transitive dependencies to see if any require selectorevent loops 
(and if any have conflicting requirements for proactor event loops, which are 
even less likely to be documented since this is now the default). Concretely, 
this is a concern for Tornado (which requires add_reader()) and applications in 
the scientific python community (including Jupyter) which depend on it. 

I know it's probably too late to do anything about this for 3.8, but it would 
be great if there were some better process to negotiate the right event loop. 
Some ideas (none of which are very satisfying):
- A declarative marker in setup.cfg or similar indicating the required feature 
set for an event loop
- A dummy package that could be depended on to indicate the same thing (and 
maybe this package could even use .pth hacks to change the default simply by 
being installed, but that seems like a hack too far)
- Some sort of runtime registry: at import time, Tornado could call 
`asyncio.add_required_features(asyncio.ADD_READER)` and this would influence 
the default policy
- Flags to `get_event_loop()` indicating the required features (passed through 
to the policy).

----------
components: asyncio
messages: 346289
nosy: Ben.Darnell, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: Configuration of windows event loop for libraries
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37373>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to