From 7b86138fd23d530b289d7e910a6d5e56e59081aa Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Sat, 4 Apr 2015 20:40:31 -0600 Subject: [PATCH] DBHub: make it a context manager --- artiq/master/worker_db.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/artiq/master/worker_db.py b/artiq/master/worker_db.py index e10266f5f..962a62de8 100644 --- a/artiq/master/worker_db.py +++ b/artiq/master/worker_db.py @@ -112,4 +112,11 @@ class DBHub: dev.close_rpc() elif hasattr(dev, "close"): dev.close() - self.active_devices = OrderedDict() + self.active_devices.clear() + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + self.close_devices() + return False # do not suppress exceptions within context