Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions pyvirtualdisplay/abstractdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,29 +307,40 @@ def _start1(self):

def _wait_for_pipe_text(self, rfd):
s = ""
# To avoid the limitation of the function select.select
# which can only accept file descriptors below 1024,
# we use select.poll.
poll = select.poll()
poll.register(rfd, select.POLLIN)

start_time = time.time()
while True:
(rfd_changed_ls, _, _) = select.select([rfd], [], [], 0.1)
rfd_changed_ls = poll.poll(0.1)
if not self.is_alive():
poll.unregister(rfd)
raise XStartError(
"%s program closed. command: %s stderr: %s"
% (self._program, self._command, self.stderr)
)
if rfd in rfd_changed_ls:
c = os.read(rfd, 1)
if c == b"\n":
break
s += c.decode("ascii")
if rfd_changed_ls:
if rfd in rfd_changed_ls[0]:
c = os.read(rfd, 1)
if c == b"\n":
break
s += c.decode("ascii")

# this timeout is for "eternal" hang. see #62
if time.time() - start_time >= self._timeout:
poll.unregister(rfd)
raise XStartTimeoutError(
"No reply from program %s. command:%s"
% (
self._program,
self._command,
)
)

poll.unregister(rfd)
return s

def _kill_subproc(self):
Expand Down