0

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?

2
  • 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/… Commented Jul 8, 2024 at 23:16
  • Not really, you can use a singleton with a map to store longer lived objects Commented Aug 2, 2024 at 11:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.