ValueError: filedescriptor out of range in select()
exarkun at divmod.com
Tue Mar 17 15:45:19 CET 2009
On Tue, 17 Mar 2009 15:04:22 +0100, Laszlo Nagy <gandalf at shopzeus.com> wrote:
>This is a long running process, written in Python. Only standard lib is
>used. This process accepts connections on TCP sockets, read/write data.
>After about one day, it starts throwing this when I try to connect:
> File "/usr/local/www/vhosts/shopzeus.com/fantasy/sorb/endpoint.py", line
>344, in read_data
> ready = select.select([fd], , , 0.2)
>ValueError: filedescriptor out of range in select()
For whatever reason, you're ending up with a lot of open files and/or sockets
(and/or any other resource based on file descriptors). That results in new
file descriptors having large values (>=1024).
You cannot use select() with such file descriptors. Try poll() instead,
or Twisted. ;)
However, the use of select() you demonstrated is an unusual one, and not
very good. It looks like the only purpose is to work around a bug in
CPython on Windows where a process in a blocking read cannot be interrupted
by C-c in the console? If that's the case, there may be other approaches
to solving the problem (like fixing the bug in CPython which causes this).
More information about the Python-list