non blocking read()

Gustavo Córdova Avila gustavo.cordova at q-voz.com
Wed Dec 1 17:17:26 EST 2004


David Bolen wrote:

>Jp Calderone <exarkun at divmod.com> writes:
>
>>    def nonBlockingReadAll(fileObj):
>>        bytes = []
>>        while True:
>>            b = fileObj.read(1024)
>>            bytes.append(b)
>>            if len(b) < 1024:
>>                break
>>        return ''.join(bytes)
>>
>Wouldn't this still block if the input just happened to end at a
>multiple of the read size (1024)?
>
>-- David
>
No, it'll read up to 1024 bytes or as much as it can, and
then return an apropriatly sized string.
-- 
Gustavo Córdova Avila <gustavo.cordova at q-voz.com> 
<mailto:gustavo.cordova at q-voz.com>
*Tel:* +52 (81) 8130-1919 ext. 127
Integraciones del Norte, S.A. de C.V.
Padua #6047, Colonia Satélite Acueducto
Monterrey, Nuevo León, México.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 264 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20041201/5a4436d9/attachment.sig>


More information about the Python-list mailing list