Skip to content

Commit 6f1dbae

Browse files
committed
posix_utils: filedescriptor out of range bugfix
replaced select.select with select.poll
1 parent 7776bf9 commit 6f1dbae

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/prompt_toolkit/input/posix_utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def __init__(
3737
self, stdin_fd: int, errors: str = "surrogateescape", encoding: str = "utf-8"
3838
) -> None:
3939
self.stdin_fd = stdin_fd
40+
self._polling_object = select.poll()
41+
self._polling_object.register(self.stdin_fd)
4042
self.errors = errors
4143

4244
# Create incremental decoder for decoding stdin.
@@ -69,7 +71,7 @@ def read(self, count: int = 1024) -> str:
6971
# function is only called when there is something to read, but for some
7072
# reason this happens in certain situations.)
7173
try:
72-
if not select.select([self.stdin_fd], [], [], 0)[0]:
74+
if not self._polling_object.poll(0): # 0 = don't block
7375
return ""
7476
except OSError:
7577
# Happens for instance when the file descriptor was closed.

0 commit comments

Comments
 (0)