Created
December 11, 2012 09:57
-
-
Save daGrevis/4257424 to your computer and use it in GitHub Desktop.
wait_or_kill.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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