Skip to content

Instantly share code, notes, and snippets.

@yiwenlu66
Created August 4, 2017 05:03
Show Gist options
  • Save yiwenlu66/b32d6c70bb7448b7b7939b59b8d5bb09 to your computer and use it in GitHub Desktop.
Save yiwenlu66/b32d6c70bb7448b7b7939b59b8d5bb09 to your computer and use it in GitHub Desktop.
A simple script to run a command as soon as a GPU is idle.
import subprocess
import time
import re
import sys
while True:
out = subprocess.check_output('nvidia-smi')
usage = int(re.search(b'\d*MiB /', out).group(0).split(b'M')[0])
if usage < 1000:
subprocess.Popen(sys.argv[1:])
break
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment