Fallstricke von Pybind11

1. Python-GIL-Sperre

Wenn der C++-Thread während des Recyclings hängen bleibt, muss die GIL-Sperre vor dem Thread-Join() aufgehoben werden, wie zum Beispiel:


#include "pybind11/pybind11.h"
#include "pybind11/stl.h"

namespace py = pybind11;

py::gil_scoped_release release;
printf("gil scoped release ...\n");
this->outputThread.join();

Hinweis: Der Gültigkeitsbereich der Variablen py::gil_scoped_release muss sicherstellen, dass join() abgeschlossen wird, wie zum Beispiel:

{
    py::gil_scoped_release release;
    printf("gil scoped release ...\n");
    this->outputThread.join();
}

おすすめ

転載: blog.csdn.net/weicao1990/article/details/134071292