小编use*_*041的帖子

Python 3;Websockets 服务器和 HTTP 服务器 - run_forever 和serve_forever

我正在尝试在同一个 python 应用程序中运行 websockets 服务器和 http 服务器。看起来我正在尝试运行两个永远循环,但第二个循环没有被激活。关于如何让这两个服务器运行有什么建议吗?

httpd = HTTPServer(('localhost', 8000), SimpleHTTPRequestHandler)

httpd.serve_forever()
asyncio.get_event_loop().run_until_complete(
    websockets.serve(echo, 'localhost', 8001))
asyncio.get_event_loop().run_forever()
Run Code Online (Sandbox Code Playgroud)

python http websocket server

7
推荐指数
1
解决办法
6062
查看次数

标签 统计

http ×1

python ×1

server ×1

websocket ×1