ollien
ollien

Reputation: 4766

Perepetual blocking of multiprocessing.Pipe()'s recv when using os.write

For some reason, the following code blocks forever

read, write = multiprocessing.Pipe()
os.write(write.fileno(), b"test\n")
print(read.recv())

but this does not

read, write = multiprocessing.Pipe()
write.send("test\n")
print(read.recv())

As far as I can tell, multiprocessing.connection.Connection.send just calls os.write under the hood, so to my eye there should be no reason for this not to work. What's going on here?

Upvotes: 0

Views: 75

Answers (1)

ollien
ollien

Reputation: 4766

Figured it out. To anyone who finds this when googling, CPython sends the size of the data as a header, which means it is waiting for an amount of data equal to the big-endian representation of 'test'.

You can see the evidence for this here and here.

Upvotes: 1

Related Questions