This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author abo
Recipients
Date 2004-05-07.05:26:57
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Currently file object's write() method returns nothing.
It would be very nice if it returned the number of
bytes written. It would also be nice if file objects
had a setblocking() method, similar to socket objects.

Under various situations, such as communicating with
popen'ed processes, write() can block. To avoid this,
you must set the file to non-blocking mode, or do
something like fork a thread to service the process so
that it can "unblock" the write.

Currently, setting a file to unblocking mode requires
using fnctl on the file objects fileno(). It would be
nice if you could directly modify this file behaviour
using a setblocking() method.

When you do set a file to non-blocking mode, the file
object's write() method will raise an exception if not
all the data could be written. This is useless, as
there is no indication how much data was successfuly
written before the blocking happened, so you have no
idea how much data remains to be written when the file
becomes unblocked.

Even using things like select() loops are not reliable,
as write() on an unblocked file can block part way
through even a small data buffer. 

The only sure way to avoid a file object's write() from
blocking or raising an unhelpful exception is to write
a single byte at a time. This means you must use
os.write() instead. The os.write() method returns the
number of bytes written, which tells how many bytes of
data remain to be written next time when the file
becomes unblocked.

The existing read() method behaves the same as the
os.read() method and can be used in non-blocking mode.
If the file write() method behaved the same as the
os.write() method, returning the number of bytes
written instead of raising an exception, then it could
also be used in non-blocking mode. 
History
Date User Action Args
2008-01-20 09:56:52adminlinkissue949667 messages
2008-01-20 09:56:52admincreate