Skip to content

Commit

Permalink
Implement non-pty #350 solution, including use of join() timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed May 30, 2016
1 parent d36bef1 commit 35620ff
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions invoke/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,13 @@ def run(self, command, **kwargs):
self.send_interrupt()
self.program_finished.set()
for t in self.threads:
t.join()
# NOTE: using a join timeout for corner case from #350 (one pipe
# excepts, fills up, prevents subproc from exiting, and other pipe
# then has a blocking read() call, causing its thread to block on
# join). In normal, non-#350 situations this should function
# similarly to a non-timeout'd join.
# TODO: make the timeout configurable
t.join(1)
e = t.exception()
if e is not None:
exceptions.append(e)
Expand Down Expand Up @@ -872,7 +878,14 @@ def wait(self):
else:
msg = "Waiting for our regular subprocess (pid {0}) to exit..."
debug(msg.format(self.process.pid))
self.process.wait()
while True:
# Popen.poll() returns None if proc is running, exitcode
# (integer) otherwise.
if self.process.poll() is not None or self.has_dead_threads:
break
# Sleep a bit so as to not hog CPU.
# TODO: refactor this & the above w/ other branch
time.sleep(self.input_sleep)

def send_interrupt(self):
if self.using_pty:
Expand Down

0 comments on commit 35620ff

Please sign in to comment.