mesa icon indicating copy to clipboard operation
mesa copied to clipboard

Server Tornado NotImplementedError Python 3.8

Open aidiss opened this issue 4 years ago • 1 comments

Describe the bug

NotImplementedError when launching server in Python 3.8

Expected behavior

No error should happen

To Reproduce

  1. Install Python3.8
  2. Create a server with ModularVisualization

Additional context

Interface starting at http://127.0.0.1:8521
Traceback (most recent call last):
  File "run.py", line 3, in <module>
    server.launch(open_browser=True)
  File "C:\Users\admin\AppData\Local\pypoetry\Cache\virtualenvs\conference-market-abm-paper-t0bN9evo-py3.8\lib\site-packages\mesa\visualization\ModularVisualization.py", line 335, in launch
    self.listen(self.port)
  File "C:\Users\admin\AppData\Local\pypoetry\Cache\virtualenvs\conference-market-abm-paper-t0bN9evo-py3.8\lib\site-packages\tornado\web.py", line 2116, in listen
    server.listen(port, address)
  File "C:\Users\admin\AppData\Local\pypoetry\Cache\virtualenvs\conference-market-abm-paper-t0bN9evo-py3.8\lib\site-packages\tornado\tcpserver.py", line 152, in listen
    self.add_sockets(sockets)
  File "C:\Users\admin\AppData\Local\pypoetry\Cache\virtualenvs\conference-market-abm-paper-t0bN9evo-py3.8\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets
    self._handlers[sock.fileno()] = add_accept_handler(
  File "C:\Users\admin\AppData\Local\pypoetry\Cache\virtualenvs\conference-market-abm-paper-t0bN9evo-py3.8\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler
    io_loop.add_handler(sock, accept_handler, IOLoop.READ)
  File "C:\Users\admin\AppData\Local\pypoetry\Cache\virtualenvs\conference-market-abm-paper-t0bN9evo-py3.8\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\admin\AppData\Local\Programs\Python\Python38\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError

Solution

The issue is known and documented here https://www.tornadoweb.org/en/stable/index.html#installation

On Windows, Tornado requires the WindowsSelectorEventLoop. This is the default in Python 3.7 and older, but Python 3.8 defaults to an event loop that is not compatible with Tornado. Applications that use Tornado on Windows with Python 3.8 must call

This can be solved by adding asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) to the beggining of ModularServer.lauch method

aidiss avatar Jun 14 '20 05:06 aidiss

Thanks for the report. Sorry it took so long, but a fix is finally coming soon.

Corvince avatar Oct 28 '20 10:10 Corvince

Fixed by #936.

rht avatar Aug 07 '23 04:08 rht