Skip to content

Commit

Permalink
tools: change asyncio_process_wait_timeout to handle cases where proc…
Browse files Browse the repository at this point in the history
…ess.stdout is None. close #56
  • Loading branch information
fallen committed Jul 7, 2015
1 parent 2d343dd commit 0109821
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions artiq/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ def asyncio_process_wait_timeout(process, timeout):
# causes a futures.InvalidStateError inside asyncio if and when the
# process terminates after the timeout.
# Work around this problem.
end_time = time.monotonic() + timeout
r = True
while r:
r = yield from asyncio.wait_for(
process.stdout.read(1024),
timeout=end_time - time.monotonic())

@asyncio.coroutine
def process_wait_returncode_timeout():
while True:
if process.returncode is not None:
break
yield from asyncio.sleep(0.1)
yield from asyncio.wait_for(process_wait_returncode_timeout(),
timeout=timeout)

@asyncio.coroutine
def asyncio_process_wait(process):
Expand Down

0 comments on commit 0109821

Please sign in to comment.