1 #include <torch/csrc/python_headers.h> 2 #include <torch/csrc/utils/object_ptr.h> 3 #include <torch/csrc/utils/pybind.h> 11 #define SYSASSERT(rv, ...) \ 13 throw std::system_error(errno, std::system_category(), ##__VA_ARGS__); \ 17 namespace multiprocessing {
21 PyObject* multiprocessing_init(PyObject* _unused) {
22 auto multiprocessing_module =
23 THPObjectPtr(PyImport_ImportModule(
"torch.multiprocessing"));
24 if (!multiprocessing_module) {
28 auto module = py::handle(multiprocessing_module).cast<py::module>();
30 module.def(
"_prctl_pr_set_pdeathsig", [](
int signal) {
31 #if defined(__linux__) 32 auto rv = prctl(PR_SET_PDEATHSIG, signal);
33 SYSASSERT(rv,
"prctl");
43 static PyMethodDef methods[] = {
45 "_multiprocessing_init",
46 (PyCFunction)multiprocessing_init,
50 {
nullptr,
nullptr, 0,
nullptr},
53 PyMethodDef* python_functions() {