Skip to content

Instantly share code, notes, and snippets.

@acrosby
Last active September 27, 2021 16:29
Show Gist options
  • Save acrosby/7752382 to your computer and use it in GitHub Desktop.
Save acrosby/7752382 to your computer and use it in GitHub Desktop.
Python alias script for retrying "optirun" if fallback fails.
#!/usr/bin/python
import subprocess, sys, shlex
#command = shlex.split(sys.argv[1])
command = "optirun " + sys.argv[1]
test = True
c = 0
while test:
print "Running", command
call = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = call.communicate()
returncode = call.returncode
if returncode == 0:
test = False
print out
elif returncode == 1:
if "deleted by window manager" in err:
break
else:
test = True
print out, err
else:
print out, err
break
print "Return Code", returncode
if c > 5:
break
else:
c += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment