tornadoweb/tornado

Prepare for python 3.8 on windows

Closed this issue ยท 14 comments

Python 3.8 asyncio is going to make the "proactor" event loop the default, instead of the current "selector" event loop. This is a problem for Tornado because the proactor event loop doesn't support the unix-style add_reader APIs that Tornado uses.

Anyone using Tornado 5+ on windows with python 3.8 will need to configure asyncio to use the selector event loop; we'll have to document this. We should also try to detect the use of a proactor event loop and give a clear error message (the current NotImplementError message can be seen in this SO post).

I don't think it would be appropriate for Tornado itself to configure the selector event loop automatically, since it has drawbacks (less scalability than the proactor loop, the user may want to use another event loop entirely like uvloop). Applications using Tornado (like jupyter notebook) may wish to do so, though. Maybe there should even be some more magical way to choose the selector loop (an environment variable? a special package to install?) to avoid the need to build this in to each application, although i don't really like the idea of that much magic.

so the ugly patch is to do this on Tornado asyncio.py

import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())  # python-3.8.0a4

what should be the external procedure (per client packages, like for example Jupyter packages) ?

I think you can do that at the beginning of your main() (or if __name__ == '__main__': etc), it does not need to be patched into a tornado module. Just somewhere before any event loop is started.

https://twitter.com/VictorStinner/status/1133323227298697216?s=09

""""
asyncio on Windows will be a much better experience in Python 3.8: IOCP event loop by default (subprocess support), CTRL+C and UDP support. https://t.co/MNpctRWma4 (outdated doc, UDP support is merged). Well done Andrew Svetlov @andrew_svetlov and others who made this possible!""

I've filed https://bugs.python.org/issue37373 upstream but it doesn't look like we'll be able to have any solution besides documenting the need for applications to set the event loop policy.

hum, let see how Jupyter team will handle the problem.

also, as a remark, trio project (and uvloop ?) somehow succeeded to make the proactorLoop work in "select" mode.

python-trio/trio@2ce3bcc

not implemented till date
import sys

if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

add above in \Lib\site-packages\tornado\platform\asyncio.py

Still appears broken.

For now you still need to use the workaround as described in the release notes.

Thanks; the workaround works.

not implemented till date
import sys

if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

add above in \Lib\site-packages\tornado\platform\asyncio.py

That worked for me, it solved an issue I had with Spyder 4.1.2 and Python 3.8 in Miniconda, thank you very much!

for completeness, here's a workaround snippet that also ensures this happens only if python version is 3.8 or more:

import sys, asyncio

if sys.version_info[0]==3 and sys.version_info[1] >= 8 and sys.platform.startswith('win'):
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

Still have the same issue

This shouldn't be happening any more with Tornado 6.1; if you're still seeing problems please open a new issue with more details.