我有一个用PyBind11
包装的c++
类。问题是:当Python
脚本结束时,c++
destructor
没有被自动调用。这会导致不整洁的退出,因为网络资源需要由析构函数释放。在
作为一种解决方法,有必要显式删除Python
对象,但我不明白为什么!在
有人能解释一下这里出了什么问题,以及在对Python
对象进行垃圾回收时如何自动调用destructor
?在
Pybind11绑定代码:
py::class_<pcs::Listener>(m, "listener")
.def(py::init<const py::object &, const std::string &, const std::string &, const std::string &, const std::string &, const std::set<std::string> &, const std::string & , const bool & , const bool & >(), R"pbdoc(
Monitors network traffic.
When a desired data source is detected a client instance is connected to consume the data stream.
Reconstructs data on receipt, like a jigsaw. Makes requests to fill any gaps. Verifies the data as sequential.
Data is output by callback to Python. Using the method specified in the constructor, which must accept a string argument.
)pbdoc");
在Python中:
^{pr2}$
目前没有回答
相关问题 更多 >
编程相关推荐