@@ -0,0 +1,1405 @@
+import os%0Aimport signal%0Aimport sys%0A%0Aclass Watcher(object):%0A    %22%22%22this class solves two problems with multithreaded%0A    programs in Python, (1) a signal might be delivered%0A    to any thread (which is just a malfeature) and (2) if%0A    the thread that gets the signal is waiting, the signal%0A    is ignored (which is a bug).%0A%0A    The watcher is a concurrent process (not thread) that%0A    waits for a signal and the process that contains the%0A    threads.  See Appendix A of The Little Book of Semaphores.%0A    http://greenteapress.com/semaphores/%0A%0A    I have only tested this on Linux.  I would expect it to%0A    work on the Macintosh and not work on Windows.%0A    %22%22%22%0A    %0A    def __init__(self):%0A        %22%22%22 Creates a child thread, which returns.  The parent%0A            thread waits for a KeyboardInterrupt and then kills%0A            the child thread.%0A        %22%22%22%0A        self.child = os.fork()%0A        if self.child == 0:%0A            return%0A        else:%0A            self.watch()%0A%0A    def watch(self):%0A        try:%0A            os.wait()%0A        except KeyboardInterrupt:%0A            # I put the capital B in KeyBoardInterrupt so I can%0A            # tell when the Watcher gets the SIGINT%0A            print 'KeyBoardInterrupt'%0A            self.kill()%0A        sys.exit()%0A%0A    def kill(self):%0A        try:%0A            os.kill(self.child, signal.SIGKILL)%0A        except OSError: pass%0A%0A%0Adef watch():%0A    Watcher()%0A

Add tools.watch module