hardware_testbench: fix timeout handling

This commit is contained in:
Robert Jördens 2016-01-28 15:41:38 -07:00
parent 982fbb0670
commit ab5e8fd8da
1 changed files with 12 additions and 13 deletions

View File

@ -24,11 +24,12 @@ class ControllerCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.device_db = DeviceDB(os.path.join(artiq_root, "device_db.pyon")) self.device_db = DeviceDB(os.path.join(artiq_root, "device_db.pyon"))
self.device_mgr = DeviceManager(self.device_db) self.device_mgr = DeviceManager(self.device_db)
self.addCleanup(self.device_mgr.close_devices)
self.controllers = {} self.controllers = {}
def tearDown(self): def tearDown(self):
self.stop_controllers() self.device_mgr.close_devices()
for name in list(self.controllers):
self.stop_controller(name)
def start_controller(self, name, sleep=1): def start_controller(self, name, sleep=1):
try: try:
@ -42,16 +43,14 @@ class ControllerCase(unittest.TestCase):
self.controllers[name] = entry, proc self.controllers[name] = entry, proc
time.sleep(sleep) time.sleep(sleep)
def stop_controllers(self): def stop_controller(self, name, default_timeout=1):
for entry, proc in self.controllers.values():
proc.terminate()
for name in list(self.controllers):
entry, proc = self.controllers[name] entry, proc = self.controllers[name]
t = entry.get("term_timeout", default_timeout)
try: try:
proc.wait(entry.get("term_timeout")) proc.wait(t)
except TimeoutError: except subprocess.TimeoutExpired:
proc.kill() proc.kill()
proc.wait(entry.get("term_timeout")) proc.wait(t)
del self.controllers[name] del self.controllers[name]