Skip to content

Prepare for python 3.8 on windows #2608

Closed

Description

@bdarnell

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.

Activity

  1. stonebig commented on May 11, 2019

    @stonebig

    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) ?

  2. ploxiln commented on May 11, 2019

    @ploxiln
    Contributor

    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.

  3. stonebig commented on May 28, 2019

    @stonebig

    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!""

  4. bdarnell commented on Jun 22, 2019

    @bdarnell
    MemberAuthor

    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.

  5. added a commit that references this issue on Jun 22, 2019
    aa879d1
  6. stonebig commented on Jun 22, 2019

    @stonebig

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

  7. added 2 commits that reference this issue on Jun 22, 2019
    4ce5829
    1bf58c7
  8. stonebig commented on Nov 3, 2019

    @stonebig

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

    python-trio/trio@2ce3bcc

  9. rajnitish commented on Nov 6, 2019

    @rajnitish

    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

  10. 4 remaining items

  11. David-OConnor commented on Apr 22, 2020

    @David-OConnor

    Still appears broken.

  12. mivade commented on Apr 22, 2020

    @mivade
    Contributor

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

  13. David-OConnor commented on Apr 23, 2020

    @David-OConnor

    Thanks; the workaround works.

  14. fbosio commented on Apr 24, 2020

    @fbosio

    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!

  15. answerquest commented on Apr 26, 2020

    @answerquest

    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())
    
  16. Crispy13 commented on Nov 30, 2020

    @Crispy13

    Still have the same issue

  17. bdarnell commented on Dec 1, 2020

    @bdarnell
    MemberAuthor

    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.

  18. added a commit that references this issue on Mar 7, 2021
  19. added a commit that references this issue on Apr 10, 2021
    6b03411
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions