ethereum / asyncio-run-in-process

A simple asyncio friendly replacement for multiprocessing to run coroutines in a separate process.
MIT License
13 stars 9 forks source link

Use `loop.connect_read_pipe` and `loop.connect_write_pipe` #2

Open pipermerriam opened 5 years ago

pipermerriam commented 5 years ago

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 the loop.connect_read_pipe to construct the appropriate StreamReader and StreamWriter instances to make this IO non-blocking and remove the need for a thread based executor.

staccDOTsol commented 1 year 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!