Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法运行 README 中计算 BMI 的示例 #15

Closed
songquanpeng opened this issue Jan 19, 2021 · 2 comments
Closed

无法运行 README 中计算 BMI 的示例 #15

songquanpeng opened this issue Jan 19, 2021 · 2 comments

Comments

@songquanpeng
Copy link

PyWebIO 版本:

PS D:\Temp\test-pywebio> pip show pywebio
Name: pywebio
Version: 1.0.1

Python 版本:

PS D:\Temp\test-pywebio> python --version
Python 3.8.3

报错信息:

PS D:\Temp\test-pywebio>  & 'C:\Users\admin\Anaconda3\python.exe' 'c:\Users\admin\.vscode\extensions\ms-python.python-2020.12.424452561\pythonFiles\lib\python\debugpy\launcher' '60851' '--' 'd:\Temp\test-pywebio\bmi.py'
Exception in thread Tornado-server:
Traceback (most recent call last): 
  File "C:\Users\admin\Anaconda3\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\admin\Anaconda3\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\admin\Anaconda3\lib\site-packages\pywebio\platform\tornado.py", line 296, in server_thread
    server, port = _setup_server(webio_handler=SingleSessionWSHandler, port=port, host='localhost')
  File "C:\Users\admin\Anaconda3\lib\site-packages\pywebio\platform\tornado.py", line 157, in _setup_server
    server = app.listen(port, address=host)
  File "C:\Users\admin\Anaconda3\lib\site-packages\tornado\web.py", line 2116, in listen
    server.listen(port, address)
  File "C:\Users\admin\Anaconda3\lib\site-packages\tornado\tcpserver.py", line 152, in listen
    self.add_sockets(sockets)
  File "C:\Users\admin\Anaconda3\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets
    self._handlers[sock.fileno()] = add_accept_handler(
  File "C:\Users\admin\Anaconda3\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler
    io_loop.add_handler(sock, accept_handler, IOLoop.READ)
  File "C:\Users\admin\Anaconda3\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\admin\Anaconda3\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError
@wang0618
Copy link
Member

这应该是python3.8 asyncio 在 windows 上默认使用的事件循环与Tornado(PyWebIO默认使用Tornado作为后端Server)不兼容造成的,见 tornadoweb/tornado#2804

可以尝试在脚本开始处加入以下代码:

import sys
import asyncio

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

@songquanpeng
Copy link
Author

it works, thx~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants