[Python-Dev] Draft PEP to make file objects support non-blocking mode.

Donovan Baarda abo at minkirri.apana.org.au
Tue Mar 22 02:17:20 CET 2005


On Mon, 2005-03-21 at 23:31 +1100, Donovan Baarda wrote:
> On Mon, 2005-03-21 at 11:42 +0100, Peter Astrand wrote:
> > On Mon, 21 Mar 2005, Donovan Baarda wrote:
> > 
> > > > > The only ways to ensure that a select process does not block like this,
> > > > > without using non-blocking mode, are;
> > 
> > > > 3) Use os.read / os.write.
> > > [...]
> > >
> > > but os.read / os.write will block too.
> > 
> > No.
> [...]
> 
> Hmmm... you are right... that changes things. Blocking vs non-blocking
> becomes kinda moot if read/write will do partial writes in blocking
> mode.
> 
> > fread() should loop internally on EAGAIN, in blocking mode.
> 
> Yeah, I was talking about non-blocking mode...

Actually, in blocking mode you never get EAGAIN.... read() only gets
EAGAIN on an empty non-blocking read().

In non-blocking mode, EAGAIN is considered an error by fread(), so it
will return a partial read. The python implementation of file.read()
will return this partial read, and clear the EAGAIN error, or raise
IOError if it was an empty read (to differentiate between an empty read
and EOF).

-- 
Donovan Baarda <abo at minkirri.apana.org.au>
http://minkirri.apana.org.au/~abo/



More information about the Python-Dev mailing list