windows下tornado报错 in add_reader raise NotImplementedError的解决

之前的代码拿过来跑,遇到报错如下:

Traceback (most recent call last):  
 File ".\index.py", line 325, in <module>     
 app.listen(8888)   
 File "C:\Program Files\Python38\lib\site-packages\tornado\web.py", line 2112, in listen     
 server.listen(port, address)   
 File "C:\Program Files\Python38\lib\site-packages\tornado\tcpserver.py", line 152, in listen     self.add_sockets(sockets)   
 File "C:\Program Files\Python38\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets     self._handlers[sock.fileno()] = add_accept_handler(   
 File "C:\Program Files\Python38\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler     io_loop.add_handler(sock, accept_handler, IOLoop.READ)  
 File "C:\Program Files\Python38\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 "C:\Program Files\Python38\lib\asyncio\events.py", line 501, in add_reader     
 raise NotImplementedError 
 NotImplementedError

是由于 python3.8 asyncio 在 windows 上默认使用 ProactorEventLoop 造成的,而不是之前的 SelectorEventLoop。jupyter 依赖 tornado,而 tornado 在 window 上需要使用 SelectorEventLoop,所以产生这个报错.

请看官方文档:https://www.tornadoweb.org/en/stable/index.html#installation

解决方法是,在 tornado开始执行前添加以下代码,在windows下单独处理:

# windows 系统下 tornado 使用 使用 SelectorEventLoop
import platform

if platform.system() == "Windows":
    import asyncio
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值