From 5df8ffe08eabb837daeeb5f442be719d087476f9 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 15 Jan 2015 11:07:55 +0800 Subject: [PATCH] master: cleaner shutdown --- artiq/master/scheduler.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/artiq/master/scheduler.py b/artiq/master/scheduler.py index 50266a9f0..94d6a00e0 100644 --- a/artiq/master/scheduler.py +++ b/artiq/master/scheduler.py @@ -108,12 +108,16 @@ class Scheduler: else: self.queue_modified.clear() self.periodic_modified.clear() - done, pend = yield from asyncio.wait( - [ - self.queue_modified.wait(), - self.periodic_modified.wait() - ], - timeout=next_periodic, - return_when=asyncio.FIRST_COMPLETED) + t1 = asyncio.Task(self.queue_modified.wait()) + t2 = asyncio.Task(self.periodic_modified.wait()) + try: + done, pend = yield from asyncio.wait( + [t1, t2], + timeout=next_periodic, + return_when=asyncio.FIRST_COMPLETED) + except: + t1.cancel() + t2.cancel() + raise for t in pend: t.cancel()