Деструктор PyBind11 не вызывается?C++

Программы на C++. Форум разработчиков
Anonymous
Деструктор PyBind11 не вызывается?

Сообщение Anonymous »

У меня есть класс C++, завернутый в PyBind11. Проблема в том, что когда сценарий Python завершает работу, деструктор C++ не вызывается автоматически. Это приводит к неаккуратному выходу, поскольку деструктору необходимо освободить сетевые ресурсы.

В качестве обходного пути необходимо явно удалить объект Python, но я не понимаю почему!

Пожалуйста, может кто-нибудь объяснить, что здесь не так и как заставить деструктор вызывать автоматически при запуске Python объект собирает мусор?

Код привязки Pybind11:

py::class_
(m, "listener")
.def(py::init(), 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:

#Function to callback
def print_string(str):
print("Python; " + str)

lstnr = listener(print_string, 'tcp://127.0.0.1:9001', clientCertPath, serverCertPath, proxyCertPath, desiredSources, 'time_series_data', enableCurve, enableVerbose)

#Run for a minute
cnt = 0
while cnt < 60:
cnt += 1
time.sleep(1)

#Need to call the destructor explicity for some reason
del lstnr


Подробнее здесь: https://stackoverflow.com/questions/554 ... ot-invoked

Вернуться в «C++»