Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def shutdown(self):
del self.master
del self.channel
self.manager.Shutdown()
del self.manager


class MyLogger(openpal.ILogHandler):
Expand Down
25 changes: 13 additions & 12 deletions src/asiodnp3/DNP3Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,22 @@

namespace py = pybind11;

template <typename T> void destroy_without_gil(T *ptr) {
pybind11::gil_scoped_release nogil;
delete ptr;
}

template <typename T> struct unique_ptr_nogil_deleter {
void operator()(T *ptr) { destroy_without_gil(ptr); }
};

void bind_DNP3Manager(py::module &m)
{
// ----- class: asiodnp3::DNP3Manager -----
py::class_<asiodnp3::DNP3Manager, std::shared_ptr<asiodnp3::DNP3Manager>>(m, "DNP3Manager",
py::class_<asiodnp3::DNP3Manager,
std::unique_ptr<asiodnp3::DNP3Manager,
unique_ptr_nogil_deleter<
asiodnp3::DNP3Manager>>>(m, "DNP3Manager",
"Root DNP3 object used to create channels and sessions.")

.def(
Expand Down Expand Up @@ -71,22 +83,11 @@ void bind_DNP3Manager(py::module &m)
py::arg("concurrencyHint"), py::arg("handler"), py::arg("onThreadStart"), py::arg("onThreadExit")
)

.def(
"__del__",
[](asiodnp3::DNP3Manager &self)
{
self.~DNP3Manager();
},
"Destructor with gil_scoped_release.",
py::call_guard<py::gil_scoped_release>()
)

.def(
"Shutdown",
[](asiodnp3::DNP3Manager &self)
{
self.Shutdown();
self.~DNP3Manager();
},
"Permanently shutdown the manager and all sub-objects that have been created. Stop the thread pool.",
py::call_guard<py::gil_scoped_release>()
Expand Down