解決Python3.8執行tornado專案報NotImplementedError錯誤
今天拉了一個使用了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 startself.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 NotImplementedErrorNotImplementedError
一番谷歌原來對於這個問題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())
這樣就可以正常運行了。
總結
到此這篇關於Python3.8執行tornado專案報NotImplementedError錯誤的文章就介紹到這了,更多相關Python3.8執行tornado專案報錯內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!