How to get number of bytes written to nonblocking FIFO when EAGAIN is raised?
Aaron Staley
usaar33 at gmail.com
Tue Jul 19 21:19:22 EDT 2011
Scenario. I have a fifo named 'fifo' on my computer (ubuntu linux)
operating in nonblocking mode for both read and write. Under normal
operation all is good:
Interpreter 1 (writer)
>>> import os
>>> fd = os.open('fifo', os.O_WRONLY | os.O_NONBLOCK)
>>> f = os.fdopen(fd,'wb')
>>> f.write('k')
>>> f.flush()
Interpreter 2 (reader):
>>> import os
>>> fd = os.open('fifo', os.O_NONBLOCK)
>>> f = os.fdopen(fd)
>>> f.read() #after f.flush was done in interpreter 1
'k'
However, if interpreter 1 overfills the FIFO, we get an error (EAGAIN)
>>> f.write('a'*70000)
IOError: [Errno 11] Resource temporarily unavailable
However interpreter 2 still receives data
>> len(f.read())
65536
It looks like interpreter 1 pushed data until the FIFO was full and
then raised the IOError. Interpreter 2 constantly received some, but
not all, of what interpreter 2 tried to send.
Unfortunately, the IOError seems to have no attribute indicating how
much data was successfully sent. I've looked through the docs and
can't seem to figure out how; can anyone land some advice?
Thanks,
Aaron Staley
More information about the Python-list
mailing list