欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

解决Python3.8运行tornado项目报NotImplementedError错误

程序员文章站 2022-06-23 14:33:39
今天拉了一个使用了tornado的项目在本地跑,按照源码作者的步骤配置完,运行,直接报错了,要求环境python3.6+,我装的是python3.8,理论上应该直接正常运行的,报错信息:traceba...

今天拉了一个使用了tornado的项目在本地跑,按照源码作者的步骤配置完,运行,直接报错了,要求环境python3.6+,我装的是python3.8,理论上应该直接正常运行的,报错信息:

traceback (most recent call last):
  file "ice_server.py", line 150, in <module>
    runserver.run_server(port=p, host=h)
  file "ice_server.py", line 125, in run_server
    tornado_server.start()
  file "d:\pycharmprojects\ice\venv\lib\site-packages\tornado\tcpserver.py", line 244, in start
    self.add_sockets(sockets)
  file "d:\pycharmprojects\ice\venv\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets
    self._handlers[sock.fileno()] = add_accept_handler(
  file "d:\pycharmprojects\ice\venv\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler
    io_loop.add_handler(sock, accept_handler, ioloop.read)
  file "d:\pycharmprojects\ice\venv\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\huan\appdata\local\programs\python\python38\lib\asyncio\events.py", line 501, in add_reader
    raise notimplementederror
notimplementederror

一番谷歌原来对于这个问题tornado的参与者们已经收到了很多反馈,有个回复里这么说:

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

大概意思python3.8asyncio改变了循环方式,因为这种方式在windows上不支持相应的add_reader apis,就会抛出notimplementederror错误。

解决办法

找到这个项目使用的python环境的lib\site-packages,做下面的修改,在path-to-python\lib\site-packages\tornado\platform\asyncio.py开头添加代码:

import sys

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

这样就可以正常运行了。

总结

到此这篇关于python3.8运行tornado项目报notimplementederror错误的文章就介绍到这了,更多相关python3.8运行tornado项目报错内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!