## lwn and wfp For the first 'job', start it with ```bash lwn JobName1 cmd arg1 arg2... ``` and for subsequent jobs (run these in separate shells) ```bash wfp JobName2 JobName1 cmd arg1 arg2 wfp JobName3 JobName1 cmd arg1 arg2 # will start at the same time as JobName2, i.e. when JobName1 finishes wfp JobName4 JobName2 cmd arg1 arg2 # will start when JobName2 finishes ``` which combines nicely with ssh, that is, ```bash ssh my_server wfp JobName4 && signal_job_done ``` where `signal_job_done` is run on my local machine and can e.g. play an alert sound or something. #### launch_with_name (aka lwn) ```python from setproctitle import setproctitle # python -m pip install setproctitle from subprocess import run import sys args = sys.argv[1:] if len(args) < 2: print(f"Not enough arguments") print(f"{sys.argv[0]} [ ...]") exit(1) title = args[0] if len(title) > 15: title = title[:15] print(f"Truncating title to '{title}'") setproctitle(args[0]) cmd = args[1:] exit(run(cmd).returncode) ``` #### wait_for_proc (aka wfp) ```python from setproctitle import setproctitle # pip install setproctitle from subprocess import run from pgrep import pgrep # pip install pgrep from time import sleep from sys import argv from datetime import datetime def now(fmt="%c"): return datetime.now().strftime(fmt) try: me, myname, targetname, *cmd = argv except ValueError: print(f"{argv[0]} [ ...]") exit(1) if len(myname) > 15: myname = myname[:15] print(f"Truncating proc name to '{myname}'") if len(targetname) > 15: targetname = targetname[:15] print(f"Truncating target name to '{targetname}'") setproctitle(myname) while pgrep(targetname): sleep(1) print(f"Waiting... {now()}",end="\r") print() if len(cmd) > 0: exit(run(cmd).returncode) else: exit(0) ```