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