forked from M-Labs/artiq
hardware_testbench: fix timeout handling
This commit is contained in:
parent
982fbb0670
commit
ab5e8fd8da
|
@ -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,17 +43,15 @@ 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():
|
entry, proc = self.controllers[name]
|
||||||
proc.terminate()
|
t = entry.get("term_timeout", default_timeout)
|
||||||
for name in list(self.controllers):
|
try:
|
||||||
entry, proc = self.controllers[name]
|
proc.wait(t)
|
||||||
try:
|
except subprocess.TimeoutExpired:
|
||||||
proc.wait(entry.get("term_timeout"))
|
proc.kill()
|
||||||
except TimeoutError:
|
proc.wait(t)
|
||||||
proc.kill()
|
del self.controllers[name]
|
||||||
proc.wait(entry.get("term_timeout"))
|
|
||||||
del self.controllers[name]
|
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(artiq_root, "no ARTIQ_ROOT")
|
@unittest.skipUnless(artiq_root, "no ARTIQ_ROOT")
|
||||||
|
|
Loading…
Reference in New Issue