From 3c70bc40a4c38640d8c9f223bf65379355da37bf Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 12 Apr 2016 15:45:30 +0800 Subject: [PATCH] master/worker_db: add pause_devices and resume_devices --- artiq/master/worker_db.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/artiq/master/worker_db.py b/artiq/master/worker_db.py index 096b2bf20..ce0862b2b 100644 --- a/artiq/master/worker_db.py +++ b/artiq/master/worker_db.py @@ -113,7 +113,9 @@ def _create_device(desc, device_mgr): class DeviceManager: """Handles creation and destruction of local device drivers and controller RPC clients.""" - def __init__(self, ddb, virtual_devices=dict()): + def __init__(self, ddb, virtual_devices=None): + if virtual_devices is None: + virtual_devices = dict() self.ddb = ddb self.virtual_devices = virtual_devices self.active_devices = OrderedDict() @@ -141,6 +143,28 @@ class DeviceManager: self.active_devices[name] = dev return dev + def pause_devices(self): + """Pauses all active devices, in the opposite order as they were + requested.""" + for dev in reversed(list(self.active_devices.values())): + if hasattr(dev.__class__, "pause"): + try: + dev.pause() + except: + logger.warning("Exception when pausing device %r", dev, + exc_info=True) + + def resume_devices(self): + """Resumes all active devices, in the same order as they were + requested.""" + for dev in self.active_devices.values(): + if hasattr(dev.__class__, "resume"): + try: + dev.resume() + except: + logger.warning("Exception when resuming device %r", dev, + exc_info=True) + def close_devices(self): """Closes all active devices, in the opposite order as they were requested.""" @@ -148,10 +172,11 @@ class DeviceManager: try: if isinstance(dev, (Client, BestEffortClient)): dev.close_rpc() - elif hasattr(dev, "close"): + elif hasattr(dev.__class__, "close"): dev.close() - except Exception as e: - logger.warning("Exception %r when closing device %r", e, dev) + except: + logger.warning("Exception when closing device %r", dev, + exc_info=True) self.active_devices.clear()