I have this decorator taken directly from an example I found on the net:
class TimedOutExc(Exception): pass def timeout(timeout): def decorate(f): def handler(signum, frame): raise TimedOutExc() def new_f(*args, **kwargs): old = signal.signal(signal.SIGALRM, handler) signal.alarm(timeout) try: result = f(*args, **kwargs) except TimedOutExc: return None finally: signal.signal(signal.SIGALRM, old) signal.alarm(0) return result new_f.func_name = f.func_name return new_f return decorate
It throws an exception if the function f expires.
Well, it works, but when I use this decorator for the multiprocessing function and stops due to a timeout, it does not interrupt the processes involved in the calculation. How can i do this?
I do not want to throw an exception and stop the program. Basically what I want, when f times, return None, and then terminate the processes involved.
source share