This is a known problem, but I want to ask the experts for the best way to solve it for me.
I have a project (Euler Math Toolbox), which runs Python as a script lan
To solve this, it would suffice to clear all variables and imports. I could live with not calling Py_Finalize. But how?
Provided you properly release all references after each call, this should work fine. Just make sure to only call Py_Initialize
a single time, and never call Py_Finalize
. Run each "session" using a separate dictionary, and always decrement the reference counts properly when you're done with them (which will release those variables after running your code).
On a side note - this is a common issue. Many other packages, such as numpy, or any package written using Boost::Python will exhibit the same behavior if you use Py_Finalize
.