forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Binding for prctl(PR_SET_PDEATHSIG) (pytorch#14491)
Summary: If torch.multiprocessing.spawn is used to launch non-daemonic processes (the default since pytorch#14391), the spawned children won't be automatically terminated when the parent terminates. On Linux, we can address this by setting PR_SET_PDEATHSIG, which delivers a configurable signal to child processes when their parent terminates. Fixes pytorch#14394. Pull Request resolved: pytorch#14491 Differential Revision: D13270374 Pulled By: pietern fbshipit-source-id: 092c9d3c3cea2622c3766b467957bc27a1bd500c
- Loading branch information
1 parent
9127ab3
commit 220ce80
Showing
8 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <torch/csrc/python_headers.h> | ||
#include <torch/csrc/utils/object_ptr.h> | ||
#include <torch/csrc/utils/pybind.h> | ||
|
||
#include <stdexcept> | ||
|
||
#if defined(__linux__) | ||
#include <sys/prctl.h> | ||
#endif | ||
|
||
#define SYSASSERT(rv, ...) \ | ||
if ((rv) < 0) { \ | ||
throw std::system_error(errno, std::system_category(), ##__VA_ARGS__); \ | ||
} | ||
|
||
namespace torch { | ||
namespace multiprocessing { | ||
|
||
namespace { | ||
|
||
PyObject* multiprocessing_init(PyObject* _unused) { | ||
auto multiprocessing_module = | ||
THPObjectPtr(PyImport_ImportModule("torch.multiprocessing")); | ||
if (!multiprocessing_module) { | ||
throw python_error(); | ||
} | ||
|
||
auto module = py::handle(multiprocessing_module).cast<py::module>(); | ||
|
||
module.def("_prctl_pr_set_pdeathsig", [](int signal) { | ||
#if defined(__linux__) | ||
auto rv = prctl(PR_SET_PDEATHSIG, signal); | ||
SYSASSERT(rv, "prctl"); | ||
#endif | ||
}); | ||
|
||
Py_RETURN_TRUE; | ||
} | ||
|
||
} // namespace | ||
|
||
// multiprocessing methods on torch._C | ||
static PyMethodDef methods[] = { | ||
{ | ||
"_multiprocessing_init", | ||
(PyCFunction)multiprocessing_init, | ||
METH_NOARGS, | ||
nullptr, | ||
}, | ||
{nullptr, nullptr, 0, nullptr}, | ||
}; | ||
|
||
PyMethodDef* python_functions() { | ||
return methods; | ||
} | ||
|
||
} // namespace multiprocessing | ||
} // namespace torch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include <torch/csrc/python_headers.h> | ||
|
||
namespace torch { | ||
namespace multiprocessing { | ||
|
||
PyMethodDef* python_functions(); | ||
|
||
} // namespace multiprocessing | ||
} // namespace torch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters