Non-exhaustive file reads

Discussion in 'Python' started by Fredrik Tolf, Dec 3, 2006.

  1. Fredrik Tolf

    Fredrik Tolf Guest

    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
     
    Fredrik Tolf, Dec 3, 2006
    #1
    1. Advertising

  2. Fredrik Tolf

    Paul Rubin Guest

    Fredrik Tolf <> writes:
    > 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?


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

    http://www.google.com/search?q=python non-blocking mode
     
    Paul Rubin, Dec 3, 2006
    #2
    1. Advertising

  3. Fredrik Tolf

    Fredrik Tolf Guest

    On Sat, 2006-12-02 at 20:00 -0800, Paul Rubin wrote:
    > Fredrik Tolf <> writes:
    > > 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?

    >
    > 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
     
    Fredrik Tolf, Dec 3, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brett Calcott

    exhaustive subsets

    Brett Calcott, May 14, 2004, in forum: Python
    Replies:
    4
    Views:
    594
    Brett Calcott
    May 16, 2004
  2. barr
    Replies:
    3
    Views:
    1,129
    Miki Tebeka
    Dec 28, 2004
  3. Mark Dufour

    slow non-blocking reads

    Mark Dufour, Jun 29, 2006, in forum: Python
    Replies:
    1
    Views:
    378
    Lawrence D'Oliveiro
    Jul 2, 2006
  4. Mark Dufour

    Re: slow non-blocking reads

    Mark Dufour, Jul 3, 2006, in forum: Python
    Replies:
    1
    Views:
    322
    Lawrence D'Oliveiro
    Jul 5, 2006
  5. Emanuele D'Arrigo

    Exhaustive Unit Testing

    Emanuele D'Arrigo, Nov 27, 2008, in forum: Python
    Replies:
    29
    Views:
    1,324
    James Harris
    Nov 30, 2008
Loading...

Share This Page