| 56 | |
| 57 | |
| 58 | def run_with_timeout(target, args=(), kwargs={}, timeout=60 * 5): |
| 59 | clear_logs() |
| 60 | result_queue = Queue() |
| 61 | wrapped_target = partial(target, result_queue=result_queue) |
| 62 | p = Process(target=wrapped_target, args=args, kwargs=kwargs) |
| 63 | p.start() |
| 64 | p.join(timeout) |
| 65 | if p.is_alive(): |
| 66 | p.terminate() |
| 67 | print_logs() |
| 68 | raise RuntimeError("Worker process hung and was terminated") |
| 69 | try: |
| 70 | result = result_queue.get(timeout=60) |
| 71 | except Exception as e: |
| 72 | raise RuntimeError(f"Failed to get result from worker: {e}") |
| 73 | finally: |
| 74 | result_queue.close() |
| 75 | result_queue.join_thread() |
| 76 | clean_ports([FD_CACHE_QUEUE_PORT]) |
| 77 | |
| 78 | return result |
| 79 | |
| 80 | |
| 81 | def form_model_get_output_topp0( |