mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: We register an [error handler](https://pybind11.readthedocs.io/en/stable/advanced/exceptions.html#registering-custom-translators) with pybind so that C++ exceptions are passed to Python and raised as runtime errors that can be `try...except`ed etc. Since these don't terminate the program (until Python does), they never fire the signal handler to write a minidump out with the crash information. This PR adds some logic in the exception translator to write out a minidump if enabled. ](https://our.intern.facebook.com/intern/diff/27830952/) Pull Request resolved: https://github.com/pytorch/pytorch/pull/55652 Pulled By: driazati Reviewed By: bertmaher Differential Revision: D27830952 fbshipit-source-id: 26e8f913e99dff971a4eb09eb87221c66f759763
22 lines
678 B
Python
22 lines
678 B
Python
import os
|
|
import sys
|
|
import pathlib
|
|
|
|
import torch
|
|
|
|
DEFAULT_MINIDUMP_DIR = "/tmp/pytorch_crashes"
|
|
|
|
def enable_minidump_collection(directory=DEFAULT_MINIDUMP_DIR):
|
|
if sys.platform != "linux":
|
|
raise RuntimeError("Minidump collection is currently only implemented for Linux platforms")
|
|
|
|
if directory == DEFAULT_MINIDUMP_DIR:
|
|
pathlib.Path(directory).mkdir(parents=True, exist_ok=True)
|
|
elif not os.path.exists(directory):
|
|
raise RuntimeError(f"Directory does not exist: {directory}")
|
|
|
|
torch._C._enable_minidump_collection(directory) # type: ignore
|
|
|
|
def disable_minidump_collection():
|
|
torch._C._disable_minidump_collection() # type: ignore
|