Created
October 2, 2012 15:52
-
-
Save phihag/3820337 to your computer and use it in GitHub Desktop.
Demo that signals don't get spread
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
from __future__ import print_function | |
import signal | |
import subprocess | |
import os | |
import sys | |
import time | |
me = sys.argv[1] if len(sys.argv) >= 2 else 'controller' | |
signal.signal(signal.SIGUSR1, lambda *args: print(me + ': SIGUSR1 caught')) | |
assert os.path.exists(__file__) | |
if me == 'controller': | |
cpid = os.fork() | |
if cpid == 0: | |
me = 'parent' | |
print('PID of ' + me + ': ' + str(os.getpid())) | |
subprocess.call(['python', __file__, 'child']) | |
else: | |
print('PID of ' + me + ': ' + str(os.getpid())) | |
time.sleep(1) | |
os.kill(cpid, signal.SIGUSR1) | |
elif me == 'child': | |
print('PID of ' + me + ': ' + str(os.getpid())) | |
time.sleep(999) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment