From 01098210781cc239be2d72c3fb7d9c9c5a5c4cf2 Mon Sep 17 00:00:00 2001 From: Yann Sionneau Date: Tue, 7 Jul 2015 19:30:13 +0200 Subject: [PATCH] tools: change asyncio_process_wait_timeout to handle cases where process.stdout is None. close #56 --- artiq/tools.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/artiq/tools.py b/artiq/tools.py index c7ddcab48..1d1f9c553 100644 --- a/artiq/tools.py +++ b/artiq/tools.py @@ -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):