Avoid extraneous copy when _recv
ing bytes through pipes in multiprocessing "connections"
#96059
Labels
_recv
ing bytes through pipes in multiprocessing "connections"
#96059
Feature or enhancement
Avoid extraneous copy when
_recv
ing bytes through pipes in multiprocessing "connections"Pitch
In the default IPC implementation of the
multiprocessing
module using pipes, theConnection._recv
method is defined as follows:cpython/Lib/multiprocessing/connection.py
Lines 378 to 392 in 586fc02
Seems like we can avoid a copy if we can read directly into a preallocated byte array? This would be beneficial if the bytes we're sending between processes are large. Another benefit here is that the
buf.write()
call above doesn't release the GIL, so in my workloads I've seen it causing stalls in another thread when trying to read from amultiprocessing.Queue
instance.Sample implementation that avoids the extraneous copy is shown below (bit untested). If it makes sense, I can submit a patch, but probably need some guidance to deal with the Windows case:
Previous discussion
N/A
The text was updated successfully, but these errors were encountered: