Skip to content

Commit cbee9c3

Browse files
committed
Added capability to not install signal handlers
1 parent 2ace2ca commit cbee9c3

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/py_bindings.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,28 @@ PYBIND11_MODULE(depthai,m)
5959
// Initial call
6060
CommonBindings::bind(m, &callstackAdapter);
6161

62+
// Install signal handler option
63+
bool installSignalHandler = true;
64+
constexpr static const char* signalHandlerKey = "DEPTHAI_INSTALL_SIGNAL_HANDLER";
65+
try {
66+
auto sysModule = py::module_::import("sys");
67+
if(py::hasattr(sysModule, signalHandlerKey)){
68+
installSignalHandler = installSignalHandler && sysModule.attr(signalHandlerKey).cast<bool>();
69+
}
70+
} catch (...) {
71+
// ignore
72+
}
73+
try {
74+
auto builtinsModule = py::module_::import("builtins");
75+
if(py::hasattr(builtinsModule, signalHandlerKey)){
76+
installSignalHandler = installSignalHandler && builtinsModule.attr(signalHandlerKey).cast<bool>();
77+
}
78+
} catch (...){
79+
// ignore
80+
}
81+
6282
// Call dai::initialize on 'import depthai' to initialize asap with additional information to print
63-
dai::initialize(std::string("Python bindings - version: ") + DEPTHAI_PYTHON_VERSION + " from " + DEPTHAI_PYTHON_COMMIT_DATETIME + " build: " + DEPTHAI_PYTHON_BUILD_DATETIME);
83+
dai::initialize(std::string("Python bindings - version: ") + DEPTHAI_PYTHON_VERSION + " from " + DEPTHAI_PYTHON_COMMIT_DATETIME + " build: " + DEPTHAI_PYTHON_BUILD_DATETIME, installSignalHandler);
6484

6585
}
6686

0 commit comments

Comments
 (0)