diff --git a/host/py_module/py_bindings.cpp b/host/py_module/py_bindings.cpp index 25834a0cb..f38a8b168 100644 --- a/host/py_module/py_bindings.cpp +++ b/host/py_module/py_bindings.cpp @@ -42,7 +42,7 @@ std::shared_ptr gl_result = nullptr; static volatile std::atomic wdog_keep; -bool deinit_device(); +bool soft_deinit_device(); bool init_device( const std::string &device_cmd_file, const std::string &usb_device @@ -55,14 +55,23 @@ static int wdog_thread_alive = 1; void wdog_thread(int& wd_timeout_ms) { std::cout << "watchdog started " << wd_timeout_ms << std::endl; + const int sleep_chunk = 100; + const int sleep_nr = wd_timeout_ms / sleep_chunk; while(wdog_thread_alive) { wdog_keep = 0; - std::this_thread::sleep_for(std::chrono::milliseconds(wd_timeout_ms)); + for(int i = 0; i < sleep_nr; i++) + { + std::this_thread::sleep_for(std::chrono::milliseconds(sleep_chunk)); + if(wdog_thread_alive == 0) + { + break; + } + } if(wdog_keep == 0 && wdog_thread_alive == 1) { std::cout << "watchdog triggered " << std::endl; - deinit_device(); + soft_deinit_device(); bool init; for(int retry = 0; retry < 1; retry++) { @@ -175,7 +184,7 @@ bool init_device( &g_xlink_device_handler, device_cmd_file, usb_device, - false) + true) ) { std::cout << "depthai: Error initializing xlink\n"; @@ -278,12 +287,23 @@ bool init_device( return result; } +bool soft_deinit_device() +{ + g_xlink = nullptr; + g_disparity_post_proc = nullptr; + g_device_support_listener = nullptr; + g_host_caputure_command = nullptr; + return true; +} + bool deinit_device() { + wdog_stop(); g_xlink = nullptr; g_disparity_post_proc = nullptr; g_device_support_listener = nullptr; g_host_caputure_command = nullptr; + gl_result = nullptr; return true; } @@ -859,7 +879,7 @@ PYBIND11_MODULE(depthai, m) .def("get_available_data_packets", &HostPipeline::getAvailableDataPackets, py::return_value_policy::copy) ; - py::class_(m, "CNNPipeline") + py::class_>(m, "CNNPipeline") .def("get_available_data_packets", &CNNHostPipeline::getAvailableDataPackets, py::return_value_policy::copy) .def("get_available_nnet_and_data_packets", &CNNHostPipeline::getAvailableNNetAndDataPackets, py::return_value_policy::copy) ; @@ -867,9 +887,7 @@ PYBIND11_MODULE(depthai, m) // module destructor auto cleanup_callback = []() { - wdog_stop(); deinit_device(); - gl_result = nullptr; }; m.add_object("_cleanup", py::capsule(cleanup_callback)); diff --git a/shared/version.hpp b/shared/version.hpp index 03ef60297..beb8532a5 100644 --- a/shared/version.hpp +++ b/shared/version.hpp @@ -1,4 +1,4 @@ #pragma once -const char *c_depthai_dev_version = "c722ebde932d6627463321816a5654b5be6069e1"; +const char *c_depthai_dev_version = "30295b558351cd030408e12a220cdd55b5fb450e"; const char *c_depthai_version = "0.0.10a"; diff --git a/shared/xlink/xlink_wrapper.cpp b/shared/xlink/xlink_wrapper.cpp index 6dfbfbb76..bc6238c01 100644 --- a/shared/xlink/xlink_wrapper.cpp +++ b/shared/xlink/xlink_wrapper.cpp @@ -25,9 +25,19 @@ XLinkWrapper::~XLinkWrapper() { if (_device_link_id != -1) { - if (_be_verbose) { printf("Stopping threads: ...\n"); } + std::chrono::steady_clock::time_point tstart; + std::chrono::duration tdiff; + if (_be_verbose) + { + printf("Stopping threads: ...\n"); + tstart = std::chrono::steady_clock::now(); + } stopThreads(); - if (_be_verbose) { printf("Stopping threads: DONE.\n"); } + if (_be_verbose) + { + tdiff = std::chrono::steady_clock::now() - tstart; + printf("Stopping threads: DONE %.3fs.\n",tdiff.count()); + } if (_be_verbose) { printf("Closing all observer streams: ...\n"); } closeAllObserverStreams(); @@ -39,6 +49,7 @@ XLinkWrapper::~XLinkWrapper() XLinkWrapper::rebootDevice(_device_link_id); } #endif + _device_link_id = -1; } } @@ -662,6 +673,7 @@ void XLinkWrapper::openAndReadDataThreadFunc( else { printf("Device get data failed: %x\n", status); + break; } std::this_thread::sleep_for(std::chrono::milliseconds(c_stream_read_thread_wait_ms));