From 97b4eb1f15de7827f23dac906920d3615c3311f9 Mon Sep 17 00:00:00 2001 From: Tristan Pinsonneault-Marotte Date: Wed, 26 Aug 2026 11:09:15 -0700 Subject: [PATCH 1/2] fix(hammer/jackhammer): Only allocate docker TTY if needed. --- sodetlib/hammers/jackhammer.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sodetlib/hammers/jackhammer.py b/sodetlib/hammers/jackhammer.py index b35e2e6c..103077ae 100644 --- a/sodetlib/hammers/jackhammer.py +++ b/sodetlib/hammers/jackhammer.py @@ -79,7 +79,7 @@ def get_docker_services(): res = subprocess.run(shlex.split(cmd), cwd=cwd, stdout=subprocess.PIPE) return res.stdout.decode().split() -def util_run(cmd, args=[], name=None, rm=True, **run_kwargs): +def util_run(cmd, args=[], name=None, rm=True, allocate_tty=False, **run_kwargs): """ Runs a command using subproces.run within the sodetlib util docker. @@ -94,12 +94,17 @@ def util_run(cmd, args=[], name=None, rm=True, **run_kwargs): set and docker-compose will choose the default. rm : bool If True, will remove the container when the command has finished. + allocate_tty : bool + If True, allow docker to allocate a pseudo-TTY. Set to True for + interactive commands (bash, ipython). Defaults to False (--no-tty) to + prevent terminal corruption when running non-interactively. run_kwargs : Additional keyword arguments Any additional kwargs specified will be passed directly to the subprocess.run function. See the subprocess docs for allowed kwargs: https://docs.python.org/3/library/subprocess.html#subprocess.run """ - cmd = f'{docker_compose_cmd} run --entrypoint={cmd} ' + tty_flag = '' if allocate_tty else '--no-tty ' + cmd = f'{docker_compose_cmd} run {tty_flag}--entrypoint={cmd} ' if name is not None: cmd += f'--name={name} ' if rm: @@ -292,7 +297,7 @@ def enter_pysmurf(slot, agg=False): util_run( 'python3', args=f"/sodetlib/scripts/start_pysmurf_ipython.py -N {slot}".split(), - name=name, rm=False + name=name, rm=False, allocate_tty=True ) def write_docker_env(): @@ -664,7 +669,7 @@ def log_func(args): # Entrypoint for jackhamer util def util_func(args): - util_run('bash', rm=(not args.detached)) + util_run('bash', rm=(not args.detached), allocate_tty=True) def gui_func(args): From 37caa8cb0ac03b156ebcd89a9665595185eba978 Mon Sep 17 00:00:00 2001 From: Tristan Pinsonneault-Marotte Date: Wed, 26 Aug 2026 11:14:18 -0700 Subject: [PATCH 2/2] fix(hammer/jackhammer): Don't use mutable defaults. --- sodetlib/hammers/jackhammer.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sodetlib/hammers/jackhammer.py b/sodetlib/hammers/jackhammer.py index 103077ae..d8d5ac1d 100644 --- a/sodetlib/hammers/jackhammer.py +++ b/sodetlib/hammers/jackhammer.py @@ -79,7 +79,7 @@ def get_docker_services(): res = subprocess.run(shlex.split(cmd), cwd=cwd, stdout=subprocess.PIPE) return res.stdout.decode().split() -def util_run(cmd, args=[], name=None, rm=True, allocate_tty=False, **run_kwargs): +def util_run(cmd, args=None, name=None, rm=True, allocate_tty=False, **run_kwargs): """ Runs a command using subproces.run within the sodetlib util docker. @@ -103,6 +103,8 @@ def util_run(cmd, args=[], name=None, rm=True, allocate_tty=False, **run_kwargs) subprocess.run function. See the subprocess docs for allowed kwargs: https://docs.python.org/3/library/subprocess.html#subprocess.run """ + if args is None: + args = [] tty_flag = '' if allocate_tty else '--no-tty ' cmd = f'{docker_compose_cmd} run {tty_flag}--entrypoint={cmd} ' if name is not None: @@ -177,7 +179,7 @@ def get_running_dockers(get_all=True): return containers -def kill_bad_dockers(slots, kill_monitor=False, names=[], images=[]): +def kill_bad_dockers(slots, kill_monitor=False, names=None, images=None): """ Kills relevant dockers for a given set of slots. @@ -191,6 +193,11 @@ def kill_bad_dockers(slots, kill_monitor=False, names=[], images=[]): images (list of strings): """ + if names is None: + names = [] + if images is None: + images = [] + print(f"Killing bad dockers for slots {slots}") bad_names = names