Created
January 7, 2014 10:53
-
-
Save romuald/8297748 to your computer and use it in GitHub Desktop.
Did I just find a bug in python locks? Or do I simply don't understands them? Signals does not wake up main thread if waiting with an indefinite time
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
""" | |
When `wait` is None, program does not receive signal (and cannot be stopped) | |
When anything else, signals wakes up main thread and stop as intended | |
""" | |
import os | |
import signal | |
from threading import Event | |
lock = Event() | |
def sighandler(signum, frame): | |
print 'got signal %d' % signum | |
lock.set() | |
signal.signal(signal.SIGTERM, sighandler) | |
signal.signal(signal.SIGINT, sighandler) | |
print 'Start with pid %d' % os.getpid() | |
wait = 10 | |
while not lock.wait(wait): | |
print 'waited %r seconds' % wait | |
print 'done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment