File "\asyncio\events.py", line 501, in add_reader raise NotImplementedError 报错解决

File “D:\Python38\lib\asyncio\events.py”, line 501, in add_reader raise NotImplementedError NotImplementedError 报错解决

Python3在使用Tornado框架时出现的问题

问题如下

Traceback (most recent call last):
  File "D:/python38_pycharm/web_server_tornado.py", line 45, in 
    http_server.add_sockets(sockets)
  File "D:\python38_pycharm\venv\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets
    self._handlers[sock.fileno()] = add_accept_handler(
  File "D:\python38_pycharm\venv\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler
    io_loop.add_handler(sock, accept_handler, IOLoop.READ)
  File "D:\python38_pycharm\venv\lib\site-packages\tornado\platform\asyncio.py", line 99, in add_handler
    self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
  File "D:\Python38\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError

File

解决方式:

找到 tornado/platform/asyncio.py 文件修改,添加代码如下:

import sys

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

你可能感兴趣的:(python)