"""this class solves two problems with multithreaded
programs in Python, (1) a signal might be delivered
to any thread (which is just a malfeature) and (2) if
the thread that gets the signal is waiting, the signal
is ignored (which is a bug).
The watcher is a concurrent process (not thread) that
waits for a signal and the process that contains the
threads. See Appendix A of The Little Book of Semaphores.
I have only tested this on Linux. I would expect it to
work on the Macintosh and not work on Windows.
""" Creates a child thread, which returns. The parent
thread waits for a KeyboardInterrupt and then kills
the child thread.
self.child = os.fork()
if self.child == 0:
# I put the capital B in KeyBoardInterrupt so I can
# tell when the Watcher gets the SIGINT
except OSError: pass