Acquire python's Global Interpreter Lock in callbacks

pull/1312/head
Stephen Shelton 4 years ago
parent a88dc9f026
commit 56e2bc2c47
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -12,6 +12,9 @@ namespace tooling
RouterHive_Init(py::module& mod) RouterHive_Init(py::module& mod)
{ {
using RouterHive_ptr = std::shared_ptr<RouterHive>; using RouterHive_ptr = std::shared_ptr<RouterHive>;
using Context_ptr = RouterHive::Context_ptr;
using ContextVisitor = std::function<void(Context_ptr)>;
py::class_<RouterHive, RouterHive_ptr>(mod, "RouterHive") py::class_<RouterHive, RouterHive_ptr>(mod, "RouterHive")
.def(py::init<>()) .def(py::init<>())
.def("AddRelay", &RouterHive::AddRelay) .def("AddRelay", &RouterHive::AddRelay)
@ -19,9 +22,30 @@ namespace tooling
.def("StartRelays", &RouterHive::StartRelays) .def("StartRelays", &RouterHive::StartRelays)
.def("StartClients", &RouterHive::StartClients) .def("StartClients", &RouterHive::StartClients)
.def("StopAll", &RouterHive::StopRouters) .def("StopAll", &RouterHive::StopRouters)
.def("ForEachRelay", &RouterHive::ForEachRelay) .def(
.def("ForEachClient", &RouterHive::ForEachClient) "ForEachRelay",
.def("ForEachRouter", &RouterHive::ForEachRouter) [](RouterHive& hive, ContextVisitor visit) {
hive.ForEachRelay([visit](Context_ptr ctx) {
py::gil_scoped_acquire acquire;
visit(std::move(ctx));
});
})
.def(
"ForEachClient",
[](RouterHive& hive, ContextVisitor visit) {
hive.ForEachClient([visit](Context_ptr ctx) {
py::gil_scoped_acquire acquire;
visit(std::move(ctx));
});
})
.def(
"ForEachRouter",
[](RouterHive& hive, ContextVisitor visit) {
hive.ForEachRouter([visit](Context_ptr ctx) {
py::gil_scoped_acquire acquire;
visit(std::move(ctx));
});
})
.def("GetNextEvent", &RouterHive::GetNextEvent) .def("GetNextEvent", &RouterHive::GetNextEvent)
.def("GetAllEvents", &RouterHive::GetAllEvents) .def("GetAllEvents", &RouterHive::GetAllEvents)
.def("RelayConnectedRelays", &RouterHive::RelayConnectedRelays) .def("RelayConnectedRelays", &RouterHive::RelayConnectedRelays)

Loading…
Cancel
Save