Skip to content

Commit

Permalink
clear containers before and after (#41)
Browse files Browse the repository at this point in the history
Signed-off-by: Tully Foote <tullyfoote@intrinsic.ai>
  • Loading branch information
tfoote authored Feb 12, 2025
1 parent 8a01f68 commit af7a1ed
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions ibpc_py/src/ibpc/ibpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
from zipfile import ZipFile
from contextlib import nullcontext

ESTIMATOR_CONTAINER = "bpc_estimator"
TESTER_CONTAINER = "bpc_tester"
ZENOH_CONTAINER = "bpc_zenoh"
DEFAULT_CONTAINER_NAMES = [ESTIMATOR_CONTAINER, ZENOH_CONTAINER, TESTER_CONTAINER]


def get_bop_template(modelname):
return f"https://huggingface.co/datasets/bop-benchmark/datasets/resolve/main/{modelname}/"
Expand All @@ -28,6 +33,22 @@ def get_ipd_template(modelname):
return f"https://huggingface.co/datasets/bop-benchmark/{modelname}/resolve/main/"


def stop_containers(containers=DEFAULT_CONTAINER_NAMES, quiet=False):
for container_name in containers:
cmd = ["docker", "kill", container_name]
if not quiet:
print(f"Running cmd {cmd}")
r = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if r.returncode != 0 and not quiet:
print(
f"Failed to stop container {container_name}. "
f"{r.stdout}"
f"{r.stderr}"
)
elif not quiet:
print(f"Successfully stopped container {container_name}")


bop_suffixes = [
"_base.zip",
"_models.zip",
Expand Down Expand Up @@ -165,7 +186,7 @@ def main():
return

tester_args = {
"name": "bpc_tester",
"name": TESTER_CONTAINER,
"network": "host",
"extension_blacklist": {},
"operating_mode": OPERATIONS_NON_INTERACTIVE,
Expand Down Expand Up @@ -193,7 +214,7 @@ def main():
return exit_code

zenoh_args = {
"name": "bpc_zenoh",
"name": ZENOH_CONTAINER,
"network": "host",
"extension_blacklist": {},
"console_output_file": "ibpc_zenoh_output.log",
Expand All @@ -214,6 +235,9 @@ def main():
def run_instance(dig_instance, args):
dig_instance.run(**args)

print("Making sure that containers are not left over from previous runs. ")
stop_containers(quiet=True)

zenoh_thread = threading.Thread(target=run_instance, args=(dig_zenoh, zenoh_args))
zenoh_thread.start()

Expand All @@ -222,7 +246,7 @@ def run_instance(dig_instance, args):
)
tester_thread.start()

args_dict["name"] = "bpc_estimator"
args_dict["name"] = ESTIMATOR_CONTAINER
args_dict["network"] = "host"
args_dict["extension_blacklist"] = ({},)
args_dict["cuda"] = True
Expand Down Expand Up @@ -253,10 +277,8 @@ def run_instance(dig_instance, args):
except KeyboardInterrupt:
# TODO clean up threads here

for container_name in ["bpc_estimator", "bpc_zenoh", "bpc_tester"]:
cmd = ["docker", "kill", container_name]
print(f"Running cmd {cmd}")
subprocess.call(cmd)
print("Stopping all containers.")
stop_containers()
tester_thread.join()
zenoh_thread.join()

Expand Down

0 comments on commit af7a1ed

Please sign in to comment.