I have a python script that calls some C++ code, and in the C++ part, I want to define some static python object, for example: static boost::python::list obj. However, according to pybind11 issue 1598 and 3274, it seems unsafe to do so, because the destructor of the static C++ object is called when the the program is exited and the python interpreter may already be in a invalid state at that time. I cant find much information about this in the doc, should I avoid static python object when using Boost.Python?
-
As said in one of the linked issues, your static object will likely call python's API after your interpreter has already been destroyed. github.com/boostorg/python/blob/…Osyotr– Osyotr2024-07-08 23:16:34 +00:00Commented Jul 8, 2024 at 23:16
-
Not really, you can use a singleton with a map to store longer lived objectsdanielm103– danielm1032024-08-02 11:50:31 +00:00Commented Aug 2, 2024 at 11:50
Add a comment
|