解决Python3.8运行tornado项目报NotImplementedError错误
作者:行星带 时间:2023-08-17 10:15:23
今天拉了一个使用了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.8
的asyncio
改变了循环方式,因为这种方式在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())
这样就可以正常运行了。
来源:https://beltxman.com/3218.html
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Pycharm中的Python Console用法解读
![](https://img.aspxhome.com/file/2023/1/101061_0s.png)
python__name__原理及用法详解
![](https://img.aspxhome.com/file/2023/5/83745_0s.png)
Python ConfigParser模块的使用示例
与ClientWidth有关的一点资料
python 读取串口数据的示例
OpenCV-Python实现图像平滑处理操作
![](https://img.aspxhome.com/file/2023/4/88924_0s.png)
你喜欢篮球吗?Python实现篮球游戏
![](https://img.aspxhome.com/file/2023/6/68456_0s.png)
asp函数遍历文件夹代码
Python 异常处理的实例详解
Scrapy爬虫Response子类在应用中的问题解析
![](https://img.aspxhome.com/file/2023/4/95834_0s.png)
Python中Pyspider爬虫框架的基本使用详解
![](https://img.aspxhome.com/file/2023/3/94053_0s.png)
远古幻想ICON 1套+创作思路
![](https://img.aspxhome.com/file/UploadPic/20079/30/2007930203644880s.jpg)
python 浮点数四舍五入需要注意的地方
![](https://img.aspxhome.com/file/2023/1/115621_0s.jpg)
PHP set_time_limit(0)长连接的实现分析
PHP中关于php.ini参数优化详解
MYSQL使用正则表达式过滤数据
![](https://img.aspxhome.com/file/2023/0/112880_0s.png)
Python字典“键”和“值”的排序5种方法
![](https://img.aspxhome.com/file/2023/7/127077_0s.png)
SQL中的开窗函数(窗口函数)
![](https://img.aspxhome.com/file/2023/3/86873_0s.jpg)
python图像处理模块Pillow的学习详解
解决Pycharm中恢复被exclude的项目问题(pycharm source root)
![](https://img.aspxhome.com/file/2023/9/120919_0s.jpg)