Open pipermerriam opened 5 years ago
Yes, you are correct. In order to make the I/O operations non-blocking and eliminate the need for a thread-based executor, you can use the loop.connect_read_pipe
and loop.connect_write_pipe
methods provided by the asyncio
library.
By using loop.connect_read_pipe
, you can establish a non-blocking read pipe and obtain a StreamReader
instance. Similarly, loop.connect_write_pipe
allows you to create a non-blocking write pipe and get a StreamWriter
instance.
These methods are useful when you want to communicate with a child process asynchronously, without blocking the event loop. By utilizing these methods, you can achieve efficient and non-blocking I/O operations within your asyncio-based application.
Please let me know if you have any further questions or need additional clarification!
https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.connect_read_pipe
Currently, the parent process uses blocking IO and
asyncio.run_in_executor
to read/write to the pipes used to communicate with the child process. It appears that we can use theloop.connect_read_pipe
to construct the appropriateStreamReader
andStreamWriter
instances to make this IO non-blocking and remove the need for a thread based executor.