1 | #include <c10/util/DeadlockDetection.h> |
---|---|
2 | |
3 | #include <cstdlib> |
4 | |
5 | namespace c10 { |
6 | namespace impl { |
7 | |
8 | namespace { |
9 | PythonGILHooks* python_gil_hooks = nullptr; |
10 | |
11 | bool disable_detection() { |
12 | return std::getenv("TORCH_DISABLE_DEADLOCK_DETECTION") != nullptr; |
13 | } |
14 | } // namespace |
15 | |
16 | bool check_python_gil() { |
17 | if (!python_gil_hooks) { |
18 | return false; |
19 | } |
20 | return python_gil_hooks->check_python_gil(); |
21 | } |
22 | |
23 | void SetPythonGILHooks(PythonGILHooks* hooks) { |
24 | if (disable_detection()) { |
25 | return; |
26 | } |
27 | TORCH_INTERNAL_ASSERT(!hooks || !python_gil_hooks); |
28 | python_gil_hooks = hooks; |
29 | } |
30 | |
31 | } // namespace impl |
32 | } // namespace c10 |
33 |