Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work on python 3.8 under Windows #148

Closed
stanmart opened this issue Jul 13, 2020 · 2 comments
Closed

Does not work on python 3.8 under Windows #148

stanmart opened this issue Jul 13, 2020 · 2 comments

Comments

@stanmart
Copy link

Hi,

My setup is the following:

# Name                    Version                   Build  Channel
python                    3.8.3           cpython_h5fd99cc_0    conda-forge
tornado                   6.0.4            py38hfa6e2cd_0    conda-forge
snakeviz                  2.0.1                      py_0    conda-forge

When using snakeviz I get the followingerror and traceback:Traceback (most recent call last):

  File "C:\Users\Martin\Miniconda3\Scripts\snakeviz-script.py", line 9, in <module>
    sys.exit(main())
  File "C:\Users\Martin\Miniconda3\lib\site-packages\snakeviz\cli.py", line 123, in main
    app.listen(p, address=hostname)
  File "C:\Users\Martin\Miniconda3\lib\site-packages\tornado\web.py", line 2116, in listen
    server.listen(port, address)
  File "C:\Users\Martin\Miniconda3\lib\site-packages\tornado\tcpserver.py", line 152, in listen
    self.add_sockets(sockets)
  File "C:\Users\Martin\Miniconda3\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets
    io_loop.add_handler(sock, accept_handler, IOLoop.READ)
  File "C:\Users\Martin\Miniconda3\lib\site-packages\tornado\platform\asyncio.py", line 100, in add_handler
    self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
  File "C:\Users\Martin\Miniconda3\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError

I believe the problem is caused by asyncio using an event loop that does not play nice with tornado's add_reader API (Tornado issue 2608). It is unclear if it will be fixed in the near future, as they believe that the event loop should be configured by applications and not tornado itself. The workaround is pretty simple. One should just add this snippet before starting the tornado server:

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

Alternatively, one could use the more elaborate function used in the jupyter notebook (jupyter/notebook commit 29ec93627c). It does essentially the same, but adds a couple more checks.

When I added one of the above options to the tornado/main.py file (after the imports) it solved the issue mentioned above. I can also submit a proper PR if you'd like.

@stanmart
Copy link
Author

Damn, I've just realized it is fixed in 2.1. I checked the open issues for duplicates, but did not think to check the closed ones as well. Turns out this issue is a duplicate of #138 and #145. Sorry!

@jiffyclub
Copy link
Owner

i got you gif

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

No branches or pull requests

2 participants