Skip to content

"filedescriptor out of range in select()" error in _ready_for_reading #354

Closed
@QuiteClose

Description

@QuiteClose

On a machine with more than 1024 open file-descriptors, the _ready_for_reading function (eventloop/posix.py) will always raise a "ValueError: filedescriptor out of range in select()".

This is because of the use of the select.select function to poll file-descriptors. A hard-limit of 1024 on any file-descriptor passed to select.select is built into Python at compile-time using the FD_SETSIZE value. On most platforms, this is 1024. An administrator may allow more file-descriptors to be opened on busy machines making the select function unreliable in posix environments.

On posix environments, the select.poll function will provide the same functionality as select in this context. It is also not limited by the FD_SETSIZE value. May I recommend switching to this function on posix environments or otherwise catching the ValueError in your _select wrapper?

This is currently preventing us from using IPython v5, as we often use machines with more than 1024 open file-descriptors. Below is a traceback from one such IPython session:

In [1]: Exception in thread Thread-97:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.5/dist-packages/prompt_toolkit/eventloop/inputhook.py", line 66, in thread
    input_is_ready_func(wait=True)
  File "/usr/local/lib/python3.5/dist-packages/prompt_toolkit/eventloop/posix.py", line 101, in ready
    return self._ready_for_reading(current_timeout[0] if wait else 0) != []
  File "/usr/local/lib/python3.5/dist-packages/prompt_toolkit/eventloop/posix.py", line 184, in _ready_for_reading
    r, _, _ =_select(read_fds, [], [], timeout)
  File "/usr/local/lib/python3.5/dist-packages/prompt_toolkit/eventloop/posix.py", line 278, in _select
    return select.select(*args, **kwargs)
ValueError: filedescriptor out of range in select()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions