windows下tornado报错inadd_readerraiseNotImplementedError的解决

编程

之前的代码拿过来跑,遇到报错如下:

Traceback (most recent call last):
  File ".index.py", line 325, in <module>
    app.listen(8888)
  File "C:Program FilesPython38libsite-packages ornadoweb.py", line 2112, in listen
    server.listen(port, address)
  File "C:Program FilesPython38libsite-packages ornado cpserver.py", line 152, in listen
    self.add_sockets(sockets)
  File "C:Program FilesPython38libsite-packages ornado cpserver.py", line 165, in add_sockets
    self._handlers[sock.fileno()] = add_accept_handler(
  File "C:Program FilesPython38libsite-packages ornado

etutil.py", line 279, in add_accept_handler
    io_loop.add_handler(sock, accept_handler, IOLoop.READ)
  File "C:Program FilesPython38libsite-packages ornadoplatformasyncio.py", line 99, in add_handler
    self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
  File "C:Program FilesPython38libasyncioevents.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError

 

是由于 python3.8 asyncio 在 windows 上默认使用 ProactorEventLoop 造成的,而不是之前的 SelectorEventLoop。jupyter 依赖 tornado,而 tornado 在 window 上需要使用 SelectorEventLoop,所以产生这个报错.

请看官方文档:https://www.tornadoweb.org/en/stable/index.html#installation

解决方法是,在 tornado开始执行前添加以下代码,在windows下单独处理:

# windows 系统下 tornado 使用 使用 SelectorEventLoop

import platform

if platform.system() == "Windows":

import asyncio

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

 

以上是 windows下tornado报错inadd_readerraiseNotImplementedError的解决 的全部内容, 来源链接: utcz.com/z/511892.html

回到顶部