I am using the multiprocessing
module to create a Process. In this child process, it will run an asyncio
event loop, and in the parent process, I am not. How can I use syncronization primitives for this pair of processes?
Let's say I want a way for the child process to wait for a message from the parent process. If I wasn't using asyncio, I would use multiprocessing.Event
. In the parent process, I create the Event
and pass it to the child process when I create it. To use, I would call event.set()
in the parent process, and in the child process I would use event.wait()
.
My understanding is that this wouldn't work in asyncio
because Event.wait
is blocking, and you can't/shouldn't ever block the asyncio event loop.
How can I write a class that works similarly to multiprocessing.Event
, but which has an async-aware wait()
method?