简体   繁体   English

为什么我的队列挂着异步事件循环

[英]Why is my queue hanging with asyncio event loop

I'm launching a new process ( edit the same thing applies to a new thread ) for computations from an async event loop.我正在为来自异步事件循环的计算启动一个新进程(编辑同样适用于新线程的内容)。 The new process has it's own asyncio event loop running and runs fine without any kind of blocking behavior.新进程有它自己的 asyncio 事件循环运行并且运行良好,没有任何类型的阻塞行为。

I created two queues ( multiprocessing.Queue or multiprocessing.Manager.Queue ), one for outgoing messages, and another for incoming messages.我创建了两个队列( multiprocessing.Queuemultiprocessing.Manager.Queue ),一个用于传出消息,另一个用于传入消息。 I get the same behavior with both queues.我对两个队列都有相同的行为。 The queue for outgoing messages is working fine, as I put/get a message on the queue with:传出消息的队列工作正常,因为我在队列上放置/获取消息:

await asyncio.get_running_loop().run_in_executor(None, self.incoming_queue.put, msg)
msg = await asyncio.get_running_loop().run_in_executor(None, self.incoming_queue.get, True, 1)

However, when I attempt to run the same get() command in my original asyncio application using the asyncio run_in_executor command, it just hangs.但是,当我尝试使用 asyncio run_in_executor命令在原始 asyncio 应用程序中运行相同的get()命令时,它只是挂起。 The event loop itself seems fine and responsive.事件循环本身似乎很好并且反应灵敏。

Disabling the working queue doesn't change things, and neither does the executor (default, thread, or process).禁用工作队列不会改变任何事情,执行程序(默认、线程或进程)也不会改变。

Ideas?想法?

I've decided to make an answer here based on my investigation.我决定根据我的调查在这里做出回答。 In short: what works in a new event loop in a new process does NOT work in the Django Channels event loop for one reason or another.简而言之:出于某种原因,在新进程中的新事件循环中起作用的内容在 Django 通道事件循环中不起作用。

My current solution is to manually create a new thread to run my synchronous listener in. I'm looking into options for why the Channels event loop wouldn't work in my use case.我当前的解决方案是手动创建一个新线程来运行我的同步侦听器。我正在研究为什么 Channels 事件循环在我的用例中不起作用的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM