Skip to content

Commit e994223

Browse files
authored
Merge pull request #404 from spacetelescope/bugfix/ServiceRunCleanup
Bugfix/service run cleanup
2 parents 5a98b16 + 76924fc commit e994223

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

catkit2/bindings.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,15 @@ PYBIND11_MODULE(catkit_bindings, m)
562562
.def_property_readonly("config", &Service::GetConfig)
563563
.def("run", [](Service &service)
564564
{
565-
service.Run(error_check_python);
566-
}, py::call_guard<py::gil_scoped_release>())
565+
{
566+
py::gil_scoped_release release;
567+
service.Run(error_check_python);
568+
}
569+
// CleanupAttributes must be called with GIL held because
570+
// m_Properties and m_Commands contain Python callbacks wrapped
571+
// in std::function. Destroying them without the GIL causes crashes.
572+
service.CleanupAttributes();
573+
})
567574
.def("open", &Service::Open)
568575
.def("main", &Service::Main)
569576
.def("close", &Service::Close)

catkit_core/Service.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,6 @@ void Service::Run(void (*error_check)())
243243

244244
ArrayInfo info{'u', '=', 8, 1, {1, 1, 1, 1}, {8, 1, 1, 1}};
245245
m_Testbed->GetMessageBroker()->PublishArray(m_ServiceId + "/heartbeat/get", {info, &timestamp});
246-
247-
248-
CleanupAttributes();
249246
}
250247

251248
void Service::CleanupAttributes()

0 commit comments

Comments
 (0)