Function
call_with_timeout
(func, *args, timeout=1, **kwargs)
Source from the content-addressed store, hash-verified
| 128 | |
| 129 | |
| 130 | def call_with_timeout(func, *args, timeout=1, **kwargs): |
| 131 | output_queue = multiprocessing.Queue() |
| 132 | process_args = args + (output_queue,) |
| 133 | process = multiprocessing.Process(target=func, args=process_args, kwargs=kwargs) |
| 134 | process.start() |
| 135 | process.join(timeout) |
| 136 | |
| 137 | if process.is_alive(): |
| 138 | process.terminate() |
| 139 | process.join() |
| 140 | return False |
| 141 | |
| 142 | return output_queue.get() |
| 143 | |
| 144 | |
| 145 | def _test_math_equal(): |
Tested by
no test coverage detected