ValueError: filedescriptor out of range in select()
Laszlo Nagy
gandalf at shopzeus.com
Tue Mar 17 13:03:59 EDT 2009
> 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. ;)
Poll is not good, because it does not wait. I cannot call poll() in a
loop and have 100% CPU used for nothing. Well of course I could call
time.sleep() if there is nothing to receive/send. But then it would
increase response times dramatically. The only thing I can use is
select.select(). Or do you have another idea?
You are talking about twisted - can someone tell me how twisted does this?
>
> 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?
Not just Ctrl+C. All of my threads are monitoring this event, and will
terminate within some seconds, if stop_requested.isSet(). This is a
multi-threaded program, and stop_requested.set() can be called from
several places:
- when a thread catches an exception that indicates an internal error in
the service
- when the program is killed, a TERM signal handler sets this event
- when Ctrl+C is pressed, in the main thread of the program
- when the program is requested to stop itself, over the network
- etc.
So for example, when I kill my program using the 'kill' command, it
cleans up everything before exiting.
I would really like to know what other options I have to implement this
efficiently. Is my approach bad?
Or am I using the wrong language? I started to use threads heavily in
the past months. Haskell might be a better choice for me, except that
Python is much more elegant. :-)
Thanks,
Laszlo
More information about the Python-list
mailing list