Skip to content

Instantly share code, notes, and snippets.

@daGrevis
Created December 11, 2012 09:57
Show Gist options
  • Select an option

  • Save daGrevis/4257424 to your computer and use it in GitHub Desktop.

Select an option

Save daGrevis/4257424 to your computer and use it in GitHub Desktop.
wait_or_kill.py
import sh
import signal
class TooLongToWait(Exception):
pass
def alarm_handler(signum, frame):
raise TooLongToWait
try:
process = sh.ls("/", _bg=True)
signal.signal(signal.SIGALRM, alarm_handler)
signal.alarm(2)
process.wait()
signal.alarm(0)
except TooLongToWait:
process.kill()
process.wait()
print "I don't have all day..."
print "I'm alive!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment