Skip to content

Commit 7f20235

Browse files
Improve tester (#245)
1 parent 9e8c71c commit 7f20235

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tests/test_pytorch_models.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright (c) 2024, Ampere Computing LLC
33
import os
4+
import signal
45
import time
56
import unittest
67
import subprocess
@@ -11,13 +12,21 @@
1112
from multiprocessing import Process, Queue
1213

1314
TIMEOUT = 3 * 60 * 60
15+
pid = os.getpid()
1416

1517

1618
def run_process(wrapper, kwargs):
19+
def wrapper_outer(**kwargs):
20+
try:
21+
wrapper(**kwargs)
22+
except Exception as e:
23+
print(f"\nException encountered: {e}")
24+
os.kill(pid, signal.SIGTERM)
25+
1726
start = time.time()
1827
output_queue = Queue()
1928
kwargs.update({"q": output_queue})
20-
p = Process(target=wrapper, kwargs=kwargs)
29+
p = Process(target=wrapper_outer, kwargs=kwargs)
2130
p.start()
2231
output = output_queue.get(block=True, timeout=max(0, int(TIMEOUT - (time.time() - start))))
2332
p.join(timeout=max(0, int(TIMEOUT - (time.time() - start))))

0 commit comments

Comments
 (0)