def dt_code_to_knot(dt_code): def dt_code_to_knot_wrapper(q, x): result = _dt_code_to_knot(x) q.put(result) q.close() q = multiprocessing.Queue(1) proc = multiprocessing.Process(target=dt_code_to_knot_wrapper, args=(q, dt_code)) proc.start() TIMEOUT = 1 try: result = q.get(True, TIMEOUT) except: LOG.warn("Timeout for knot identification exceeded, assuming no knot") result = None finally: proc.terminate() return result