Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call previous excepthook in tvm_excepthook. #5675

Merged
merged 4 commits into from
May 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us modify the function as tvm_wrap_excepthook(exception_hook) that returns a new wrapped hook, and then do

sys.excepthook = tvm_wrap_exceptionhook(sys.except_hook)

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)