Skip to content

Commit cb7050c

Browse files
ghostplanttqchen
authored andcommitted
Quit and clean when TVM is interrupted (#3640)
1 parent 0d61113 commit cb7050c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

python/tvm/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
"""TVM: Low level DSL/IR stack for tensor computation."""
1919
from __future__ import absolute_import as _abs
2020

21+
import multiprocessing
22+
import sys
23+
import traceback
24+
2125
from . import _pyversion
2226

2327
from . import tensor
@@ -59,3 +63,13 @@
5963

6064
# Contrib initializers
6165
from .contrib import rocm as _rocm, nvcc as _nvcc, sdaccel as _sdaccel
66+
67+
# Clean subprocesses when TVM is interrupted
68+
def tvm_excepthook(exctype, value, trbk):
69+
print('\n'.join(traceback.format_exception(exctype, value, trbk)))
70+
if hasattr(multiprocessing, 'active_children'):
71+
# pylint: disable=not-callable
72+
for p in multiprocessing.active_children():
73+
p.terminate()
74+
75+
sys.excepthook = tvm_excepthook

0 commit comments

Comments
 (0)