草庐IT

Asyncio库

全部标签

python - 使用 asyncio 的非阻塞 I/O

我正在尝试使用Pygame和asyncio编写网络游戏,但我不知道如何避免挂起读取。这是我的客户代码:@asyncio.coroutinedefhandle_client():print("Connected!")reader,writer=yieldfromasyncio.open_connection('localhost',8000)whileTrue:mouse_up=Falseforeventinpygame.event.get():ifevent.type==pygame.QUIT:pygame.quit()sys.exit()elifevent.type==pygame.

python - 使用 asyncio 的非阻塞 I/O

我正在尝试使用Pygame和asyncio编写网络游戏,但我不知道如何避免挂起读取。这是我的客户代码:@asyncio.coroutinedefhandle_client():print("Connected!")reader,writer=yieldfromasyncio.open_connection('localhost',8000)whileTrue:mouse_up=Falseforeventinpygame.event.get():ifevent.type==pygame.QUIT:pygame.quit()sys.exit()elifevent.type==pygame.

Python - 在单独的子进程或线程中运行 Autobahn|Python asyncio websocket 服务器

我有一个在Python3.4.1中运行的基于tkinter的GUI程序。我在程序中运行了几个线程来从各种url获取JSON数据。我想添加一些WebSocket功能,以便能够允许程序充当服务器并允许多个客户端通过WebSocket连接到它并交换其他JSON数据。我正在尝试将Autobahn|PythonWebSocket服务器用于异步。我首先尝试在GUI程序下的单独线程中运行asyncio事件循环。但是,每次尝试都会给出'AssertionError:Thereisnocurrenteventloopinthread'Thread-1'。然后我尝试使用标准库多处理包生成一个进程,该包在另

Python - 在单独的子进程或线程中运行 Autobahn|Python asyncio websocket 服务器

我有一个在Python3.4.1中运行的基于tkinter的GUI程序。我在程序中运行了几个线程来从各种url获取JSON数据。我想添加一些WebSocket功能,以便能够允许程序充当服务器并允许多个客户端通过WebSocket连接到它并交换其他JSON数据。我正在尝试将Autobahn|PythonWebSocket服务器用于异步。我首先尝试在GUI程序下的单独线程中运行asyncio事件循环。但是,每次尝试都会给出'AssertionError:Thereisnocurrenteventloopinthread'Thread-1'。然后我尝试使用标准库多处理包生成一个进程,该包在另

python - 如何将 Celery 与 asyncio 结合使用?

如何创建一个使celery任务看起来像asyncio.Task的包装器?或者有没有更好的方法将Celery与asyncio集成?@asksol,Celery的创造者,saidthis::It'squitecommontouseCeleryasadistributedlayerontopofasyncI/Oframeworks(toptip:routingCPU-boundtaskstoapreforkworkermeanstheywillnotblockyoureventloop).但我找不到任何专门针对asyncio框架的代码示例。 最佳答案

python - 如何将 Celery 与 asyncio 结合使用?

如何创建一个使celery任务看起来像asyncio.Task的包装器?或者有没有更好的方法将Celery与asyncio集成?@asksol,Celery的创造者,saidthis::It'squitecommontouseCeleryasadistributedlayerontopofasyncI/Oframeworks(toptip:routingCPU-boundtaskstoapreforkworkermeanstheywillnotblockyoureventloop).但我找不到任何专门针对asyncio框架的代码示例。 最佳答案

Python - 如何使用 asyncio 同时运行多个协程?

我正在使用websockets在Python3.4中创建websocket服务器的库。这是一个简单的回显服务器:importasyncioimportwebsockets@asyncio.coroutinedefconnection_handler(websocket,path):whileTrue:msg=yieldfromwebsocket.recv()ifmsgisNone:#connectionlostbreakyieldfromwebsocket.send(msg)start_server=websockets.serve(connection_handler,'localh

Python - 如何使用 asyncio 同时运行多个协程?

我正在使用websockets在Python3.4中创建websocket服务器的库。这是一个简单的回显服务器:importasyncioimportwebsockets@asyncio.coroutinedefconnection_handler(websocket,path):whileTrue:msg=yieldfromwebsocket.recv()ifmsgisNone:#connectionlostbreakyieldfromwebsocket.send(msg)start_server=websockets.serve(connection_handler,'localh

python - 为什么 asyncio 的事件循环会抑制 Windows 上的 KeyboardInterrupt?

我有一个非常小的测试程序,除了执行asyncio事件循环之外什么都不做:importasyncioasyncio.get_event_loop().run_forever()当我在Linux上运行此程序并按Ctrl+C时,程序将正确终止并出现KeyboardInterrupt异常。在Windows上按Ctrl+C什么都不做(用Python3.4.2测试)。time.sleep()的简单无限循环即使在Windows上也能正确引发KeyboardInterrupt:importtimewhileTrue:time.sleep(3600)为什么asyncio的事件循环会抑制Windows上的

python - 为什么 asyncio 的事件循环会抑制 Windows 上的 KeyboardInterrupt?

我有一个非常小的测试程序,除了执行asyncio事件循环之外什么都不做:importasyncioasyncio.get_event_loop().run_forever()当我在Linux上运行此程序并按Ctrl+C时,程序将正确终止并出现KeyboardInterrupt异常。在Windows上按Ctrl+C什么都不做(用Python3.4.2测试)。time.sleep()的简单无限循环即使在Windows上也能正确引发KeyboardInterrupt:importtimewhileTrue:time.sleep(3600)为什么asyncio的事件循环会抑制Windows上的