readline() blocks after select() says there's data??
Grant Edwards
grante at visi.com
Sat Mar 16 00:44:41 EST 2002
In article <a6tdvl$19mg$1 at nntp6.u.washington.edu>, Donn Cave wrote:
> Quoth grante at visi.com (Grant Edwards):
>| In article <mailman.1016212173.16075.python-list at python.org>, Rich Cook wrote:
> ...
>|> So do I have to read the data byte by byte using read(1) and
>|> examine each character to avoid blocking? Is there any way to
>|> find out how much data is actually waiting for me in the file
>|> object so I can read it in bigger increments, or must I call
>|> select then read(1) for every byte?
>|
>| You don't have to read it 1 byte at a time. Just call
>| f.read(1024) and it will give you however many bytes are
>| available, up to the max of 1024. You can use a max different
>| than 1024 if you want.
>
> I think you're making the problem worse here.
>
> import popen2
> t = popen2.Popen3('echo L1; sleep 2; echo L2; sleep 2; echo L3')
> print 'First read: ', repr(t.fromchild.read(1024))
>
> $ python /tmp/x
> First read: 'L1\nL2\nL3\n'
>
> C I/O basically sucks for this application. When you ask for 1024,
> fread is bound to get that amount, just as it is if you ask for a
> line via fgets ("readline".) If you omit the amount, you're asking
> for all the data, won't return until the socket's other end closes.
Sorry, with all the talk of sockets, I was thinking of the recv() call.
--
Grant Edwards grante Yow! -- In 1962, you could
at buy a pair of SHARKSKIN
visi.com SLACKS, with a "Continental
Belt," for $10.99!!
More information about the Python-list
mailing list