worker: close devices immediately after run and before analyze

This commit is contained in:
Sebastien Bourdeauducq 2015-03-20 12:01:34 +01:00
parent 577754c38f
commit 200e20fb39
3 changed files with 6 additions and 9 deletions

View File

@ -178,7 +178,7 @@ def main():
key=itemgetter(0)): key=itemgetter(0)):
print("{}: {}".format(k, v)) print("{}: {}".format(k, v))
finally: finally:
dbh.close() dbh.close_devices()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -104,16 +104,12 @@ class DBHub:
self.active_devices[name] = dev self.active_devices[name] = dev
return dev return dev
def close(self): def close_devices(self):
"""Closes all active devices, in the opposite order as they were """Closes all active devices, in the opposite order as they were
requested. requested."""
Do not use the same ``DBHub`` again after calling
this function.
"""
for dev in reversed(list(self.active_devices.values())): for dev in reversed(list(self.active_devices.values())):
if isinstance(dev, (Client, BestEffortClient)): if isinstance(dev, (Client, BestEffortClient)):
dev.close_rpc() dev.close_rpc()
elif hasattr(dev, "close"): elif hasattr(dev, "close"):
dev.close() dev.close()
self.active_devices = OrderedDict()

View File

@ -116,6 +116,7 @@ def main():
put_object({"action": "completed"}) put_object({"action": "completed"})
elif action == "run": elif action == "run":
exp_inst.run() exp_inst.run()
dbh.close_devices()
put_object({"action": "completed"}) put_object({"action": "completed"})
elif action == "analyze": elif action == "analyze":
exp_inst.analyze() exp_inst.analyze()
@ -130,7 +131,7 @@ def main():
elif action == "terminate": elif action == "terminate":
break break
finally: finally:
dbh.close() dbh.close_devices()
if __name__ == "__main__": if __name__ == "__main__":
main() main()