Skip to content

Instantly share code, notes, and snippets.

@jamesrr39
Created August 16, 2025 21:55
Show Gist options
  • Save jamesrr39/f39b6e4ead1314bf19f5847fcee65d3d to your computer and use it in GitHub Desktop.
Save jamesrr39/f39b6e4ead1314bf19f5847fcee65d3d to your computer and use it in GitHub Desktop.
wait-until-done
#!python3
import os
import argparse
import time
parser = argparse.ArgumentParser(
prog='wait-until-done',
description='Waits until a process has completed. Usage like "python3 wait-until-done 1234 && do-next-command". Use "ps aux" to get the Process ID you are looking for.')
parser.add_argument('pid')
parser.add_argument('--interval-seconds', type=int, default=10)
args = parser.parse_args()
initial_exists = os.path.exists("/proc/{}".format(args.pid))
if initial_exists is False:
raise Exception("/proc/{} did not exist at the beginning".format(args.pid))
while True:
time.sleep(args.interval_seconds)
exists = os.path.exists("/proc/{}".format(args.pid))
if exists is False:
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment