Skip to content

Commit ab5e8fd

Browse files
committedJan 28, 2016
hardware_testbench: fix timeout handling
1 parent 982fbb0 commit ab5e8fd

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed
 

Diff for: ‎artiq/test/hardware_testbench.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ class ControllerCase(unittest.TestCase):
2424
def setUp(self):
2525
self.device_db = DeviceDB(os.path.join(artiq_root, "device_db.pyon"))
2626
self.device_mgr = DeviceManager(self.device_db)
27-
self.addCleanup(self.device_mgr.close_devices)
2827
self.controllers = {}
2928

3029
def tearDown(self):
31-
self.stop_controllers()
30+
self.device_mgr.close_devices()
31+
for name in list(self.controllers):
32+
self.stop_controller(name)
3233

3334
def start_controller(self, name, sleep=1):
3435
try:
@@ -42,17 +43,15 @@ def start_controller(self, name, sleep=1):
4243
self.controllers[name] = entry, proc
4344
time.sleep(sleep)
4445

45-
def stop_controllers(self):
46-
for entry, proc in self.controllers.values():
47-
proc.terminate()
48-
for name in list(self.controllers):
49-
entry, proc = self.controllers[name]
50-
try:
51-
proc.wait(entry.get("term_timeout"))
52-
except TimeoutError:
53-
proc.kill()
54-
proc.wait(entry.get("term_timeout"))
55-
del self.controllers[name]
46+
def stop_controller(self, name, default_timeout=1):
47+
entry, proc = self.controllers[name]
48+
t = entry.get("term_timeout", default_timeout)
49+
try:
50+
proc.wait(t)
51+
except subprocess.TimeoutExpired:
52+
proc.kill()
53+
proc.wait(t)
54+
del self.controllers[name]
5655

5756

5857
@unittest.skipUnless(artiq_root, "no ARTIQ_ROOT")

0 commit comments

Comments
 (0)