mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-28 20:53:35 +08:00
dbhub: do not use as context manager, turn close exceptions into warnings, do not close devices early in worker
This commit is contained in:
parent
0ec7e9a98c
commit
9b46bc623a
@ -154,12 +154,15 @@ def run(with_file=False):
|
||||
pdb = FlatFileDB(args.pdb)
|
||||
pdb.hooks.append(SimpleParamLogger())
|
||||
rdb = ResultDB(lambda description: None, lambda mod: None)
|
||||
dbh = DBHub(ddb, pdb, rdb)
|
||||
|
||||
with DBHub(ddb, pdb, rdb) as dbh:
|
||||
try:
|
||||
exp_inst = _build_experiment(dbh, args)
|
||||
rdb.build()
|
||||
exp_inst.run()
|
||||
exp_inst.analyze()
|
||||
finally:
|
||||
dbh.close_devices()
|
||||
|
||||
if args.hdf5 is not None:
|
||||
with h5py.File(args.hdf5, "w") as f:
|
||||
|
@ -1,11 +1,15 @@
|
||||
from collections import OrderedDict
|
||||
import importlib
|
||||
import logging
|
||||
|
||||
from artiq.protocols.sync_struct import Notifier
|
||||
from artiq.protocols.pc_rpc import Client, BestEffortClient
|
||||
from artiq.master.results import result_dict_to_hdf5
|
||||
|
||||
|
||||
logger = logging.get_logger(__name__)
|
||||
|
||||
|
||||
class ResultDB:
|
||||
def __init__(self, init_rt_results, update_rt_results):
|
||||
self.init_rt_results = init_rt_results
|
||||
@ -108,15 +112,11 @@ class DBHub:
|
||||
"""Closes all active devices, in the opposite order as they were
|
||||
requested."""
|
||||
for dev in reversed(list(self.active_devices.values())):
|
||||
if isinstance(dev, (Client, BestEffortClient)):
|
||||
dev.close_rpc()
|
||||
elif hasattr(dev, "close"):
|
||||
dev.close()
|
||||
try:
|
||||
if isinstance(dev, (Client, BestEffortClient)):
|
||||
dev.close_rpc()
|
||||
elif hasattr(dev, "close"):
|
||||
dev.close()
|
||||
except Exception as e:
|
||||
logger.warning("Exception %r when closing device %r", e, dev)
|
||||
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
|
||||
|
@ -97,8 +97,9 @@ def main():
|
||||
exp_inst = None
|
||||
|
||||
rdb = ResultDB(init_rt_results, update_rt_results)
|
||||
dbh = DBHub(ParentDDB, ParentPDB, rdb)
|
||||
|
||||
with DBHub(ParentDDB, ParentPDB, rdb) as dbh:
|
||||
try:
|
||||
while True:
|
||||
obj = get_object()
|
||||
action = obj["action"]
|
||||
@ -115,7 +116,6 @@ def main():
|
||||
put_object({"action": "completed"})
|
||||
elif action == "run":
|
||||
exp_inst.run()
|
||||
dbh.close_devices()
|
||||
put_object({"action": "completed"})
|
||||
elif action == "analyze":
|
||||
exp_inst.analyze()
|
||||
@ -129,6 +129,8 @@ def main():
|
||||
put_object({"action": "completed"})
|
||||
elif action == "terminate":
|
||||
break
|
||||
finally:
|
||||
dbh.close_devices()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user