Skip to content

Commit

Permalink
Call previous excepthook in tvm_excepthook. (#5675)
Browse files Browse the repository at this point in the history
* Call previous excepthook in tvm_excepthook.

* Rename prev_excepthook.

* Create a tvm_wrap_excepthook to wrap a given excepthook with tvm custom excepthook work
and call it on system previous excepthook.

* Add docstring.
  • Loading branch information
notoraptor authored May 27, 2020
1 parent af162c4 commit 07449f5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions python/tvm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,17 @@
# Contrib initializers
from .contrib import rocm as _rocm, nvcc as _nvcc, sdaccel as _sdaccel

# Clean subprocesses when TVM is interrupted
def tvm_excepthook(exctype, value, trbk):
print('\n'.join(traceback.format_exception(exctype, value, trbk)))
if hasattr(multiprocessing, 'active_children'):
# pylint: disable=not-callable
for p in multiprocessing.active_children():
p.terminate()
def tvm_wrap_excepthook(exception_hook):
"""Wrap given excepthook with TVM additional work."""

sys.excepthook = tvm_excepthook
def wrapper(exctype, value, trbk):
"""Clean subprocesses when TVM is interrupted."""
exception_hook(exctype, value, trbk)
if hasattr(multiprocessing, 'active_children'):
# pylint: disable=not-callable
for p in multiprocessing.active_children():
p.terminate()

return wrapper

sys.excepthook = tvm_wrap_excepthook(sys.excepthook)

0 comments on commit 07449f5

Please sign in to comment.