views:

105

answers:

2

Here's a snippet of code I'm using in a loop:

while True:
    print 'loop'
    rlist, wlist, xlist = select.select(readers, [], [], TIMEOUT)
    print 'selected'
    # do stuff

At a certain point, select will block and "selected" is never getting printed. What can cause this behavior? Is it possible there's some kind of deadlock?

UPDATE: I'm running on Ubuntu linux and the reader objects are sockets.

+1  A: 

Some longshots...

If TIMEOUT is getting set to None, then select will never timeout. Also, if readers becomes an empty list, select will always wait for the full timeout value (or hang if TIMEOUT is None)

Peter Shinners
+2  A: 

Yes, depending on the OS in question, it is indeed possible for a certain file descriptor to block at OS level in a non-interruptible way even though you've explicitly demanded for it to be non-blocking. Depending on your OS, there may be workarounds to these OS-level bugs (or "misfeatures"), but to offer any further help we need to know exactly what OS is in play and exactly what kinds of objects are in the readers list.

Alex Martelli
Updated. I'm using Ubuntu Jaunty and the objects in readers are sockets.
Jason Baker
@Jason, weird -- I can't imagine what would cause such deadlocks in your excellent operating environment. Maybe see if using select.poll or select.epoll is a workaround...?
Alex Martelli