Re: ValueError: filedescriptor out of range in select()

Discussion in 'Python' started by Laszlo Nagy, Mar 17, 2009.

  1. Laszlo Nagy

    Laszlo Nagy Guest

    > 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 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. :)


    Laszlo Nagy, Mar 17, 2009
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paolo Invernizzi

    filedescriptor out of range in select()

    Paolo Invernizzi, Jun 26, 2003, in forum: Python
    Paolo Invernizzi
    Jun 26, 2003
  2. Andrew Bennetts

    Re: filedescriptor out of range in select()

    Andrew Bennetts, Jun 26, 2003, in forum: Python
    Paolo Invernizzi
    Jun 30, 2003
  3. Laszlo Nagy
    Laszlo Nagy
    Mar 17, 2009
  4. k3xji
    Steven D'Aprano
    Sep 16, 2010
  5. Isaac Won
    Isaac Won
    Feb 6, 2013

Share This Page