解決Python3.8運行tornado項目報NotImplementedError錯誤
今天拉了一個使用了tornado的項目在本地跑,按照源碼作者的步驟配置完,運行,直接報錯了,要求環(huán)境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改變了循環(huán)方式,因為這種方式在windows上不支持相應的add_reader APIs,就會拋出NotImplementedError錯誤。
解決辦法
找到這個項目使用的python環(huán)境的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項目報錯內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
python使用multiprocessing模塊實現(xiàn)帶回調函數(shù)的異步調用方法
這篇文章主要介紹了python使用multiprocessing模塊實現(xiàn)帶回調函數(shù)的異步調用方法,實例分析了multiprocessing模塊異步調用的相關使用技巧,需要的朋友可以參考下2015-04-04
利用python為PostgreSQL的表自動添加分區(qū)
這篇文章主要介紹了利用python為PostgreSQL的表自動添加分區(qū),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-01-01
python環(huán)境功能強大的pip-audit安全漏洞掃描工具
這篇文章主要為大家介紹了python環(huán)境中功能強大的pip-audit安全漏洞掃描工具的功能介紹及安裝使用說明,有需要的朋友可以借鑒參考下,希望能夠有所幫助2022-02-02

