Skip to content

Instantly share code, notes, and snippets.

@dnephin
Last active December 30, 2015 16:16
Show Gist options
  • Save dnephin/a0a7a155fdea2ba17627 to your computer and use it in GitHub Desktop.
Save dnephin/a0a7a155fdea2ba17627 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -x
cat > tmp.py <<EOF
import os, signal
print os.getpid()
state = None
def handler(sig, frame):
global state
print "caught"
oldstate = state
state = "new"
if oldstate:
print "second"
else:
print "first"
signal.signal(signal.SIGTERM, handler)
while True:
pass
EOF
python tmp.py &
pid=$!
sleep 0.1
parallel kill $pid ::: $pid ::: $pid
sleep 0.5
kill -9 $pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment