开发者

What can cause select to block in Python?

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 开发者_StackOverflowstuff

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.


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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜