forked from M-Labs/artiq
1
0
Fork 0

master/worker_impl: Factor out "completed" message sending [nfc]

Just reduces the visual complexity/potential for typos a bit, and
we already have put_exception_report().
This commit is contained in:
David Nadlinger 2020-06-15 00:23:48 +01:00
parent 2429a266f6
commit d87042597a
1 changed files with 11 additions and 6 deletions

View File

@ -213,6 +213,11 @@ def setup_diagnostics(experiment_file, repository_path):
artiq.coredevice.core._DiagnosticEngine.render_diagnostic = \ artiq.coredevice.core._DiagnosticEngine.render_diagnostic = \
render_diagnostic render_diagnostic
def put_completed():
put_object({"action": "completed"})
def put_exception_report(): def put_exception_report():
_, exc, _ = sys.exc_info() _, exc, _ = sys.exc_info()
# When we get CompileError, a more suitable diagnostic has already # When we get CompileError, a more suitable diagnostic has already
@ -281,14 +286,14 @@ def main():
os.chdir(dirname) os.chdir(dirname)
argument_mgr = ProcessArgumentManager(expid["arguments"]) argument_mgr = ProcessArgumentManager(expid["arguments"])
exp_inst = exp((device_mgr, dataset_mgr, argument_mgr, {})) exp_inst = exp((device_mgr, dataset_mgr, argument_mgr, {}))
put_object({"action": "completed"}) put_completed()
elif action == "prepare": elif action == "prepare":
exp_inst.prepare() exp_inst.prepare()
put_object({"action": "completed"}) put_completed()
elif action == "run": elif action == "run":
run_time = time.time() run_time = time.time()
exp_inst.run() exp_inst.run()
put_object({"action": "completed"}) put_completed()
elif action == "analyze": elif action == "analyze":
try: try:
exp_inst.analyze() exp_inst.analyze()
@ -297,7 +302,7 @@ def main():
# write results afterwards # write results afterwards
put_exception_report() put_exception_report()
else: else:
put_object({"action": "completed"}) put_completed()
elif action == "write_results": elif action == "write_results":
filename = "{:09}-{}.h5".format(rid, exp.__name__) filename = "{:09}-{}.h5".format(rid, exp.__name__)
with h5py.File(filename, "w") as f: with h5py.File(filename, "w") as f:
@ -307,10 +312,10 @@ def main():
f["start_time"] = start_time f["start_time"] = start_time
f["run_time"] = run_time f["run_time"] = run_time
f["expid"] = pyon.encode(expid) f["expid"] = pyon.encode(expid)
put_object({"action": "completed"}) put_completed()
elif action == "examine": elif action == "examine":
examine(ExamineDeviceMgr, ExamineDatasetMgr, obj["file"]) examine(ExamineDeviceMgr, ExamineDatasetMgr, obj["file"])
put_object({"action": "completed"}) put_completed()
elif action == "terminate": elif action == "terminate":
break break
except: except: