select() call and filedescriptor out of range in select error
Ned Deily
nad at acm.org
Thu Sep 16 00:49:14 EDT 2010
In article
<bafd7b25-8a4a-4ef9-b839-adc42b62d9d7 at i17g2000vbq.googlegroups.com>,
k3xji <sumerc at gmail.com> wrote:
> We have a select-based server written in Python. Occasionally, maybe
> twice a month there occurs a weird problem, select() returns with
> filedescriptor out of range in select() error. This is of course a
> normal error and handled gracefully. Our policy is to take down few
> users for select() to handle the next cycle. However, once this error
> occurs, this also fails too:
>
> self.__Sockets.remove(socket)
>
> self.__Socket's is the very basic list of sockets we use in our IO
> loop. The call fails with:
> remove(x): x not in list
>
> First of all, in our entire application there is no line of code like
> remove(x), meaning there is no x variable. Second, the Exception shows
> the line number containing above code. So
> self.__Sockets.remove(socket) this fails with remove(x): x not in
> list....
>
> I cannot understand the problem. It happens in sporadic manner and it
> feels that the ValueError of select() call somehow corrupts the List
> structure itself in Python? Not sure if something like that is
> possible.
That error message is a generic exception message. It just means the
object to be removed is not in the list. For example:
>>> l = [a, b]
>>> a, b = 1, 2
>>> l = [a, b]
>>> l.remove(a)
>>> l.remove(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: list.remove(x): x not in list
If the problem is that the socket object in question no longer exists,
you can protect your code there by enclosing the remove operation in a
try block, like:
try:
self.__Sockets.remove(socket)
except ValueError:
pass
--
Ned Deily,
nad at acm.org
More information about the Python-list
mailing list