Skip to content

Commit e3c97fd

Browse files
tfooteYadunund
authored andcommitted
Simple approach to clean up threads (#34)
1 parent 87d45f3 commit e3c97fd

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

ibpc_py/src/ibpc/ibpc.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def main():
167167
return
168168

169169
tester_args = {
170+
"name": "bpc_tester",
170171
"network": "host",
171172
"extension_blacklist": {},
172173
"operating_mode": OPERATIONS_NON_INTERACTIVE,
@@ -194,6 +195,7 @@ def main():
194195
return exit_code
195196

196197
zenoh_args = {
198+
"name": "bpc_zenoh",
197199
"network": "host",
198200
"extension_blacklist": {},
199201
"console_output_file": "ibpc_zenoh_output.log",
@@ -214,14 +216,15 @@ def main():
214216
def run_instance(dig_instance, args):
215217
dig_instance.run(**args)
216218

217-
tester_thread = threading.Thread(target=run_instance, args=(dig_zenoh, zenoh_args))
218-
tester_thread.start()
219+
zenoh_thread = threading.Thread(target=run_instance, args=(dig_zenoh, zenoh_args))
220+
zenoh_thread.start()
219221

220222
tester_thread = threading.Thread(
221223
target=run_instance, args=(dig_tester, tester_args)
222224
)
223225
tester_thread.start()
224226

227+
args_dict["name"] = "bpc_estimator"
225228
args_dict["network"] = "host"
226229
args_dict["extension_blacklist"] = ({},)
227230

@@ -244,6 +247,18 @@ def run_instance(dig_instance, args):
244247
args_dict["command"] = "/bin/bash"
245248
args_dict["mode"] = OPERATIONS_INTERACTIVE
246249

247-
result = dig.run(**args_dict)
248-
# TODO clean up threads here
249-
return result
250+
try:
251+
result = dig.run(**args_dict)
252+
return result
253+
254+
except KeyboardInterrupt:
255+
# TODO clean up threads here
256+
257+
for container_name in ["bpc_estimator", "bpc_zenoh", "bpc_tester"]:
258+
cmd = ["docker", "kill", container_name]
259+
print(f"Running cmd {cmd}")
260+
subprocess.call(cmd)
261+
tester_thread.join()
262+
zenoh_thread.join()
263+
264+
return -1

0 commit comments

Comments
 (0)