Skip to content

Commit

Permalink
posix_utils: filedescriptor out of range bugfix
Browse files Browse the repository at this point in the history
replaced select.select with select.poll
  • Loading branch information
jstucke committed Feb 8, 2023
1 parent 7776bf9 commit 6f1dbae
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/prompt_toolkit/input/posix_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def __init__(
self, stdin_fd: int, errors: str = "surrogateescape", encoding: str = "utf-8"
) -> None:
self.stdin_fd = stdin_fd
self._polling_object = select.poll()
self._polling_object.register(self.stdin_fd)
self.errors = errors

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

0 comments on commit 6f1dbae

Please sign in to comment.