I've been unsuccessfully looking for an alternative for signals, that works in threads.
After updating a script of mine from being single-threaded to being multi-threaded, I realised that signals do not work in threads. I've used signals to handle blocking operations that possibly take forever like: signal.signal(signal.SIGALRM, wait_timeout) # wait_timeout simply does: raise Exception("timeout") signal.setitimer(signal.ITIMER_REAL,5) # So a timer of 5 seconds start and I run my operation try: p = Popen(["tool", "--param"], stdin=PIPE, stdout=PIPE, stderr=STDOUT) for line in p.stdout: if "STRING" in str(line): signal.setitimer(signal.ITIMER_REAL,0) p.terminate() print("Success") except: p.terminate() print("Timeout") Now this works great with a single thread, but doesn't work at all with multiple threads. A more throughout example can be found here: https://gist.github.com/saatomic/841ddf9c5142a7c75b03daececa8eb17 What can I use instead of signals in this case? Thanks and kind regards, SaAtomic -- https://mail.python.org/mailman/listinfo/python-list