Skip to content

Instantly share code, notes, and snippets.

@jbbarth
Last active January 4, 2017 05:01
Show Gist options
  • Save jbbarth/b63b21b98dd6ac32e2820a7c948c2f0e to your computer and use it in GitHub Desktop.
Save jbbarth/b63b21b98dd6ac32e2820a7c948c2f0e to your computer and use it in GitHub Desktop.
time.sleep() immediately returns when a signal is received
import time
import signal
def abrt_handler(signum, frame):
print "Hey I catched a signal {}".format(signum)
signal.signal(signal.SIGABRT, abrt_handler)
while True:
time.sleep(5)
print "... stil sleeping"
@jbbarth
Copy link
Author

jbbarth commented Jan 4, 2017

To test it once:

pkill -ABRT -f sigabrt.py

And for the more violent version:

while [ 1 ]; do pkill -ABRT -f sigabrt.py; done

(and Ctrl+C to stop, since SIGINT is not catched)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment