Skip to content

Commit

Permalink
Add timeout to avoid hanging on python interface tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hansec committed Nov 22, 2023
1 parent 330a5c1 commit 0232aa6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/tests/physics/test_TokaMaker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import print_function
import os
import sys
import time
import multiprocessing
import json
import pytest
Expand All @@ -12,10 +13,21 @@
from OpenFUSIONToolkit.TokaMaker import TokaMaker, gs_Domain, save_gs_mesh, load_gs_mesh


def mp_run(target,args):
def mp_run(target,args,timeout=30):
mp_q = multiprocessing.Queue()
p = multiprocessing.Process(target=target, args=args + (mp_q,))
p.start()
start = time.time()
while time.time() - start <= timeout:
if not p.is_alive():
break
time.sleep(.5)
else: # Reached timeout
print("Timeout reached")
p.terminate()
p.join()
return None
# Completed successfully
test_result = mp_q.get()
p.join()
return test_result
Expand Down

0 comments on commit 0232aa6

Please sign in to comment.