Commit dc089610 authored by legoc's avatar legoc Committed by Shervin Nourbakhsh
Browse files

Added necessary functions with call_guard policy py::gil_scoped_release to...

Added necessary functions with call_guard policy py::gil_scoped_release to avoid blocking python threads
parent 35783413
...@@ -39,12 +39,12 @@ PYBIND11_MODULE(cameopy, m) { ...@@ -39,12 +39,12 @@ PYBIND11_MODULE(cameopy, m) {
m.attr("SUCCESS") = SUCCESS; m.attr("SUCCESS") = SUCCESS;
m.attr("STOPPED") = STOPPED; m.attr("STOPPED") = STOPPED;
m.attr("KILLED") = KILLED; m.attr("KILLED") = KILLED;
/*
py::enum_<cameo::Option>(m, "Option")
.value("NONE", cameo::NONE) // Important note:
.value("OUTPUTSTREAM", cameo::OUTPUTSTREAM) // The call_guard policy is set to py::gil_scoped_release for all bindings except for getters and setters that use a local member of the object.
.export_values(); // If the policy is not set, the bindings are blocking other Python running threads.
*/
py::class_<This>(m, "This") py::class_<This>(m, "This")
.def( .def(
"init", "init",
...@@ -54,9 +54,9 @@ PYBIND11_MODULE(cameopy, m) { ...@@ -54,9 +54,9 @@ PYBIND11_MODULE(cameopy, m) {
for (auto& s : args) for (auto& s : args)
cstrs.push_back(const_cast<char*>(s.c_str())); cstrs.push_back(const_cast<char*>(s.c_str()));
This::init(args.size(), cstrs.data()); This::init(args.size(), cstrs.data());
}, }, py::call_guard<py::gil_scoped_release>(),
"initialize the application") "initialize the application")
.def("terminate", &This::terminate) .def("terminate", &This::terminate, py::call_guard<py::gil_scoped_release>())
.def("getName", &This::getName) .def("getName", &This::getName)
.def("getId", &This::getId) .def("getId", &This::getId)
.def("setTimeout", &This::setTimeout) .def("setTimeout", &This::setTimeout)
...@@ -65,14 +65,14 @@ PYBIND11_MODULE(cameopy, m) { ...@@ -65,14 +65,14 @@ PYBIND11_MODULE(cameopy, m) {
.def("getServer", &This::getServer, py::return_value_policy::reference) .def("getServer", &This::getServer, py::return_value_policy::reference)
.def("getCom", &This::getCom) .def("getCom", &This::getCom)
.def("getStarterServer", &This::getStarterServer) .def("getStarterServer", &This::getStarterServer)
.def("isAvailable", &This::isAvailable) //, py::arg("timeout") = 1000) // this does not work! .def("isAvailable", &This::isAvailable, py::call_guard<py::gil_scoped_release>()) //, py::arg("timeout") = 1000) // this does not work!
.def("isStopping", &This::isStopping) .def("isStopping", &This::isStopping, py::call_guard<py::gil_scoped_release>())
// .def("handleStop", &This::handleStop) // .def("handleStop", &This::handleStop)
.def("cancelWaitings", &This::cancelWaitings) .def("cancelWaitings", &This::cancelWaitings, py::call_guard<py::gil_scoped_release>())
.def("setRunning", &This::setRunning) .def("setRunning", &This::setRunning, py::call_guard<py::gil_scoped_release>())
.def("setBinaryResult", &This::setBinaryResult) .def("setBinaryResult", &This::setBinaryResult, py::call_guard<py::gil_scoped_release>())
.def("setResult", &This::setResult) .def("setResult", &This::setResult, py::call_guard<py::gil_scoped_release>())
.def("connectToStarter", &This::connectToStarter); .def("connectToStarter", &This::connectToStarter, py::call_guard<py::gil_scoped_release>());
py::class_<Instance>(m, "Instance") py::class_<Instance>(m, "Instance")
.def("getName", &Instance::getName) .def("getName", &Instance::getName)
...@@ -83,15 +83,15 @@ PYBIND11_MODULE(cameopy, m) { ...@@ -83,15 +83,15 @@ PYBIND11_MODULE(cameopy, m) {
.def("hasResult", &Instance::hasResult) .def("hasResult", &Instance::hasResult)
.def("exists", &Instance::exists) .def("exists", &Instance::exists)
.def("getErrorMessage", &Instance::getErrorMessage) .def("getErrorMessage", &Instance::getErrorMessage)
.def("stop", &Instance::stop) .def("stop", &Instance::stop, py::call_guard<py::gil_scoped_release>())
.def("kill", &Instance::kill) .def("kill", &Instance::kill, py::call_guard<py::gil_scoped_release>())
.def("waitFor", py::overload_cast<>(&Instance::waitFor), py::call_guard<py::gil_scoped_release>()) .def("waitFor", py::overload_cast<>(&Instance::waitFor), py::call_guard<py::gil_scoped_release>())
.def("waitFor", py::overload_cast<int>(&Instance::waitFor), py::call_guard<py::gil_scoped_release>()) .def("waitFor", py::overload_cast<int>(&Instance::waitFor), py::call_guard<py::gil_scoped_release>())
.def("waitFor", py::overload_cast<const std::string&>(&Instance::waitFor), py::call_guard<py::gil_scoped_release>()) .def("waitFor", py::overload_cast<const std::string&>(&Instance::waitFor), py::call_guard<py::gil_scoped_release>())
.def("cancelWaitFor", &Instance::cancelWaitFor) .def("cancelWaitFor", &Instance::cancelWaitFor, py::call_guard<py::gil_scoped_release>())
.def("getLastState", &Instance::getLastState) .def("getLastState", &Instance::getLastState, py::call_guard<py::gil_scoped_release>())
.def("getActualState", &Instance::getActualState) .def("getActualState", &Instance::getActualState, py::call_guard<py::gil_scoped_release>())
.def("getPastStates", &Instance::getPastStates) .def("getPastStates", &Instance::getPastStates, py::call_guard<py::gil_scoped_release>())
.def("getExitCode", &Instance::getExitCode) .def("getExitCode", &Instance::getExitCode)
.def("getBinaryResult", .def("getBinaryResult",
[](Instance* instance) { [](Instance* instance) {
...@@ -99,28 +99,28 @@ PYBIND11_MODULE(cameopy, m) { ...@@ -99,28 +99,28 @@ PYBIND11_MODULE(cameopy, m) {
if (result.has_value() == false) if (result.has_value() == false)
return py::bytes(""); return py::bytes("");
return py::bytes(result.value()); return py::bytes(result.value());
}) }, py::call_guard<py::gil_scoped_release>())
.def("getResult", &Instance::getResult) .def("getResult", &Instance::getResult, py::call_guard<py::gil_scoped_release>())
.def("getOutputStreamSocket", &Instance::getOutputStreamSocket); .def("getOutputStreamSocket", &Instance::getOutputStreamSocket);
py::class_<InstanceArray>(m, "InstanceArray"); py::class_<InstanceArray>(m, "InstanceArray");
py::class_<Publisher>(m, "Publisher") py::class_<Publisher>(m, "Publisher")
.def("create", &Publisher::create, py::arg("numberOfSubscribers") = 0) .def("create", &Publisher::create, py::arg("numberOfSubscribers") = 0, py::call_guard<py::gil_scoped_release>())
.def("getName", &Publisher::getName) .def("getName", &Publisher::getName)
.def("getApplicationName", &Publisher::getApplicationName) .def("getApplicationName", &Publisher::getApplicationName)
.def("getApplicationId", &Publisher::getApplicationId) .def("getApplicationId", &Publisher::getApplicationId)
.def("getApplicationEndpoint", &Publisher::getApplicationEndpoint) .def("getApplicationEndpoint", &Publisher::getApplicationEndpoint)
.def("waitForSubscribers", &Publisher::waitForSubscribers, py::call_guard<py::gil_scoped_release>()) .def("waitForSubscribers", &Publisher::waitForSubscribers, py::call_guard<py::gil_scoped_release>())
.def("cancelWaitForSubscribers", &Publisher::cancelWaitForSubscribers) .def("cancelWaitForSubscribers", &Publisher::cancelWaitForSubscribers, py::call_guard<py::gil_scoped_release>())
.def("sendBinary", &Publisher::sendBinary) .def("sendBinary", &Publisher::sendBinary, py::call_guard<py::gil_scoped_release>())
.def("send", &Publisher::send) .def("send", &Publisher::send, py::call_guard<py::gil_scoped_release>())
.def("sendTwoBinaryParts", &Publisher::sendTwoBinaryParts) .def("sendTwoBinaryParts", &Publisher::sendTwoBinaryParts, py::call_guard<py::gil_scoped_release>())
.def("sendEnd", &Publisher::sendEnd) .def("sendEnd", &Publisher::sendEnd, py::call_guard<py::gil_scoped_release>())
.def("isEnded", &Publisher::isEnded); .def("isEnded", &Publisher::isEnded);
py::class_<Subscriber>(m, "Subscriber") py::class_<Subscriber>(m, "Subscriber")
.def("create", &Subscriber::create) .def("create", &Subscriber::create, py::call_guard<py::gil_scoped_release>())
.def("getPublisherName", &Subscriber::getPublisherName) .def("getPublisherName", &Subscriber::getPublisherName)
.def("getInstanceName", &Subscriber::getInstanceName) .def("getInstanceName", &Subscriber::getInstanceName)
.def("getInstanceId", &Subscriber::getInstanceId) .def("getInstanceId", &Subscriber::getInstanceId)
...@@ -130,7 +130,7 @@ PYBIND11_MODULE(cameopy, m) { ...@@ -130,7 +130,7 @@ PYBIND11_MODULE(cameopy, m) {
.def("receiveBinary", &Subscriber::receiveBinary, py::call_guard<py::gil_scoped_release>()) .def("receiveBinary", &Subscriber::receiveBinary, py::call_guard<py::gil_scoped_release>())
.def("receive", &Subscriber::receive, py::call_guard<py::gil_scoped_release>()) .def("receive", &Subscriber::receive, py::call_guard<py::gil_scoped_release>())
.def("receiveTwoBinaryParts", &Subscriber::receiveTwoBinaryParts, py::call_guard<py::gil_scoped_release>()) .def("receiveTwoBinaryParts", &Subscriber::receiveTwoBinaryParts, py::call_guard<py::gil_scoped_release>())
.def("cancel", &Subscriber::cancel); .def("cancel", &Subscriber::cancel, py::call_guard<py::gil_scoped_release>());
py::class_<Request>(m, "Request") py::class_<Request>(m, "Request")
.def("getObjectId", &Request::getObjectId) .def("getObjectId", &Request::getObjectId)
...@@ -139,29 +139,29 @@ PYBIND11_MODULE(cameopy, m) { ...@@ -139,29 +139,29 @@ PYBIND11_MODULE(cameopy, m) {
.def("get", &Request::get) .def("get", &Request::get)
.def("getSecondBinaryPart", &Request::getSecondBinaryPart) .def("getSecondBinaryPart", &Request::getSecondBinaryPart)
.def("setTimeout", &Request::setTimeout) .def("setTimeout", &Request::setTimeout)
.def("replyBinary", &Request::replyBinary) .def("replyBinary", &Request::replyBinary, py::call_guard<py::gil_scoped_release>())
.def("reply", &Request::reply) .def("reply", &Request::reply, py::call_guard<py::gil_scoped_release>())
.def("connectToRequester", &Request::connectToRequester) .def("connectToRequester", &Request::connectToRequester, py::call_guard<py::gil_scoped_release>())
// the following require "Server.h" // the following require "Server.h"
.def("getServer", &Request::getServer); .def("getServer", &Request::getServer);
py::class_<Responder>(m, "Responder") py::class_<Responder>(m, "Responder")
.def("create", &Responder::create) .def("create", &Responder::create, py::call_guard<py::gil_scoped_release>())
.def("getName", &Responder::getName) .def("getName", &Responder::getName)
.def("cancel", &Responder::cancel) .def("cancel", &Responder::cancel, py::call_guard<py::gil_scoped_release>())
.def("receive", &Responder::receive, py::call_guard<py::gil_scoped_release>()) .def("receive", &Responder::receive, py::call_guard<py::gil_scoped_release>())
.def("isCanceled", &Responder::isCanceled); .def("isCanceled", &Responder::isCanceled);
py::class_<Requester>(m, "Requester") py::class_<Requester>(m, "Requester")
.def("create", &Requester::create) .def("create", &Requester::create, py::call_guard<py::gil_scoped_release>())
.def("getName", &Requester::getName) .def("getName", &Requester::getName)
.def("sendBinary", &Requester::sendBinary) .def("sendBinary", &Requester::sendBinary, py::call_guard<py::gil_scoped_release>())
.def("send", &Requester::send) .def("send", &Requester::send, py::call_guard<py::gil_scoped_release>())
.def("sendTwoBinaryParts", &Requester::sendTwoBinaryParts) .def("sendTwoBinaryParts", &Requester::sendTwoBinaryParts, py::call_guard<py::gil_scoped_release>())
.def("receiveBinary", &Requester::receiveBinary, py::call_guard<py::gil_scoped_release>()) .def("receiveBinary", &Requester::receiveBinary, py::call_guard<py::gil_scoped_release>())
.def("receive", &Requester::receive, py::call_guard<py::gil_scoped_release>()) .def("receive", &Requester::receive, py::call_guard<py::gil_scoped_release>())
.def("cancel", &Requester::cancel) .def("cancel", &Requester::cancel, py::call_guard<py::gil_scoped_release>())
.def("isCanceled", &Requester::isCanceled); .def("isCanceled", &Requester::isCanceled);
...@@ -195,21 +195,19 @@ PYBIND11_MODULE(cameopy, m) { ...@@ -195,21 +195,19 @@ PYBIND11_MODULE(cameopy, m) {
.def("getTimeout", &cameo::Server::getTimeout) .def("getTimeout", &cameo::Server::getTimeout)
.def("getEndpoint", &cameo::Server::getEndpoint) .def("getEndpoint", &cameo::Server::getEndpoint)
.def("getVersion", &cameo::Server::getVersion) .def("getVersion", &cameo::Server::getVersion)
.def("isAvailable", py::overload_cast<>(&cameo::Server::isAvailable, py::const_)) .def("isAvailable", py::overload_cast<>(&cameo::Server::isAvailable, py::const_), py::call_guard<py::gil_scoped_release>())
.def("isAvailable", py::overload_cast<int>(&cameo::Server::isAvailable, py::const_)) .def("isAvailable", py::overload_cast<int>(&cameo::Server::isAvailable, py::const_), py::call_guard<py::gil_scoped_release>())
.def("start", py::overload_cast<const std::string&, int>(&cameo::Server::start)) .def("start", py::overload_cast<const std::string&, int>(&cameo::Server::start), py::call_guard<py::gil_scoped_release>())
.def("start", py::overload_cast<const std::string&, const std::vector<std::string>&, int>( .def("start", py::overload_cast<const std::string&, const std::vector<std::string>&, int>(&cameo::Server::start), py::call_guard<py::gil_scoped_release>())
&cameo::Server::start)) .def("connectAll", &cameo::Server::connectAll, py::call_guard<py::gil_scoped_release>())
.def("connectAll", &cameo::Server::connectAll) .def("connect", py::overload_cast<const std::string&, int>(&cameo::Server::connect), py::call_guard<py::gil_scoped_release>())
.def("connect", py::overload_cast<const std::string&, int>(&cameo::Server::connect)) .def("connect", py::overload_cast<int, int>(&cameo::Server::connect), py::call_guard<py::gil_scoped_release>())
.def("connect", py::overload_cast<int, int>(&cameo::Server::connect)) .def("killAllAndWaitFor", &cameo::Server::killAllAndWaitFor, py::call_guard<py::gil_scoped_release>())
.def("killAllAndWaitFor", &cameo::Server::killAllAndWaitFor) .def("getApplicationConfigurations", &cameo::Server::getApplicationConfigurations, py::call_guard<py::gil_scoped_release>())
.def("getApplicationConfigurations", &cameo::Server::getApplicationConfigurations) .def("getApplicationInfos", py::overload_cast<>(&cameo::Server::getApplicationInfos, py::const_), py::call_guard<py::gil_scoped_release>())
.def("getApplicationInfos", py::overload_cast<>(&cameo::Server::getApplicationInfos, py::const_)) .def("getApplicationInfos", py::overload_cast<const std::string&>(&cameo::Server::getApplicationInfos, py::const_), py::call_guard<py::gil_scoped_release>())
.def("getApplicationInfos", .def("getPorts", &cameo::Server::getPorts, py::call_guard<py::gil_scoped_release>())
py::overload_cast<const std::string&>(&cameo::Server::getApplicationInfos, py::const_)) .def("getActualState", &cameo::Server::getActualState, py::call_guard<py::gil_scoped_release>())
.def("getPorts", &cameo::Server::getPorts) .def("getPastStates", &cameo::Server::getPastStates, py::call_guard<py::gil_scoped_release>())
.def("getActualState", &cameo::Server::getActualState) .def("openEventStream", &cameo::Server::openEventStream, py::call_guard<py::gil_scoped_release>());
.def("getPastStates", &cameo::Server::getPastStates)
.def("openEventStream", &cameo::Server::openEventStream);
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment