select() interruption by signal

Cliff Daniel cdaniel at Level3.net
Mon Oct 11 14:39:46 EDT 1999


Specify a timeout value in select() of 1 second.  Every time 
through the loop check the time and determine if it's time
to do some chores outside of select().  Something like:

while 1:
    ### Call select with a timeout of 1 second
    ### Select will return in 1 second if nothing on read/exception set
    (r,w,e) = select.select(fd_list, [], fd_list, 1) 

    Now = time.time()
    if Now > LastChore:
	DoChores()
	LastChore = time.time() + 2

    for fd in r:
	# Do other stuff

Regards,
Cliff


Robert Longstaff <spooky at dreamfish.freeserve.co.uk> writes:
> In my app I have a select() call inside a continuous loop waiting for 
> asynchronous data input from various connected sources. As this call blocks 
> and I need to perform other mini tasks I have an alarm call that fires 
> every 2s that is reset inside its handler.
> 
> However I've found that this alarm signal, although being caught 
> successfully by the handler, also interrupts the select() causing the app 
> to bomb out:
> 
> Traceback (innermost last):
>   File "./myapp.py", line 169, in ?
>     inList, outList, specialList = select.select(select_mask, [], [])
> select.error: (4, 'Interrupted system call')
> 
> Is this just a timing thing? Is the select() 'catching' the signal at the 
> same time as the handler or is the signal 'hanging around' longer than it 
> should?
> 
> Is there an option to get the select() to ignore signals or should I trap 
> the exception (and throw it away)? I can't find any more information in the 
> Python manual or man select. I'm using v1.5.1 on Linux.
> 
> Thanks in advance.
> 
> Robert.
> 
> P.S. I thought I'd ask this as a more 'general' question before including 
> any source.
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list