timeout with read operations

googleboy mynews44 at yahoo.com
Thu Jul 22 13:46:03 EDT 2004


jim_8421 at hotmail.com (Jim) wrote in message news:<c5694ea3.0407211519.62a56f1a at posting.google.com>...
> Hi,
> 
> I am trying to figure out a way to implement a timeout along with a
> read() call on an open file.  It only has to work on linux,
> for now I am trying:
> 
> ret = select.select( [fileno],[],[], timeout )
> if ret[0] == [fileno]
>     # do read
> 
> but .. what if between the select and read call something happens and
> the read blocks indefinitly?
> Is there a way I can have a functions like file.read( timeout ), where
> timeout out is a gauranteed lower bound?  I know that there is for
> sockets, with the settimeout function, but I don't know how they
> implemented it.


Could you not use signals to do what you need?

Someone just pointed me in that direction,  and it worked great for
me.  About 5 lines of code.

http://www.python.org/doc/current/lib/module-signal.html

Check the example out.  

I hope I have helped!   I am usually the n00b asking the questions
around here.

googleboy



More information about the Python-list mailing list