Non-exhaustive file reads

F

Fredrik Tolf

I just got shocked to find out the hard way that the read() method on
Python's file objects will, very much unlike the C read() function, read
until the given size is reached, which is quite a problem for me when
selecting a couple of pipes and wanting to just read the available data
from them.

The only hint I can find for avoiding this behavior is from
file.read.__doc__, which says that it doesn't do that in non-blocking
mode, but nowhere can I find any information about how to enable
non-blocking mode in Python.

Can anyone provide me with any information on how to accomplish this?

Regards,
Fredrik Tolf
 
F

Fredrik Tolf

In Linux you'd use fcntl. Some other discussion can be found on the
web:

I was looking for os.fcntl() without finding it, but now that you
reassured me, I found the fcntl module instead.

However, I also found os.read() in the process, which might be a better
alternative (since I can just use it normally like in C without setting
extra fd flags or anything).

Thanks!

Fredrik Tolf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top