mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
Summary:
Currently there's an #ifdef USE_DEPLOY to disable deadlock detection in torch for torch deploy. We want to be able to link against binary distributions of PyTorch so we need to have a way to disable deadlock detection at runtime.
55f55a4cf6/torch/csrc/autograd/python_variable.cpp (L1017)
Test Plan: buck test //caffe2/c10/test:util_base_test
Differential Revision: D36303256
Pull Request resolved: https://github.com/pytorch/pytorch/pull/77270
Approved by: https://github.com/PaliC
32 lines
658 B
C++
32 lines
658 B
C++
#include <c10/util/DeadlockDetection.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <cstdlib>
|
|
|
|
using namespace ::testing;
|
|
using namespace c10::impl;
|
|
|
|
struct DummyPythonGILHooks : public PythonGILHooks {
|
|
bool check_python_gil() const override {
|
|
return true;
|
|
}
|
|
};
|
|
|
|
TEST(DeadlockDetection, basic) {
|
|
ASSERT_FALSE(check_python_gil());
|
|
DummyPythonGILHooks hooks;
|
|
SetPythonGILHooks(&hooks);
|
|
ASSERT_TRUE(check_python_gil());
|
|
SetPythonGILHooks(nullptr);
|
|
}
|
|
|
|
#ifndef _WIN32
|
|
TEST(DeadlockDetection, disable) {
|
|
setenv("TORCH_DISABLE_DEADLOCK_DETECTION", "1", 1);
|
|
DummyPythonGILHooks hooks;
|
|
SetPythonGILHooks(&hooks);
|
|
SetPythonGILHooks(&hooks);
|
|
}
|
|
#endif
|