If I'm right calling Py_Finalize();
will clear the python interpreter (some exceptions are found on [1]).
I would suggest you to create a class for the python interpreter and to manually check all your tasks are finished before calling Py_Finalize();
. In the projects where I have worked using the embedded python interpreter, this was suiting the best.
Hope it helps!
[Python Doc][1]
https://docs.python.org/2/c-api/init.html
== EDIT ==
For Py_Finalize()
Bugs and caveats: The destruction of modules and objects in modules is
done in random order; this may cause destructors (del() methods)
to fail when they depend on other objects (even functions) or modules.
Dynamically loaded extension modules loaded by Python are not
unloaded. Small amounts of memory allocated by the Python interpreter
may not be freed (if you find a leak, please report it). Memory tied
up in circular references between objects is not freed. Some memory
allocated by extension modules may not be freed. Some extensions may
not work properly if their initialization routine is called more than
once; this can happen if an application calls Py_Initialize and
Py_Finalize more than once.
Seems like if your program is only calling Py_Initialize() and Py_Finalize() once, you might find some trouble (which I never did) and have some memory leak. However if you are only Initializing the python interpreter and performing tasks while your main program is running (I'm more familiar to this approach) you won't have many trouble.