[C++-sig] PyFinalize Safety
paul at mustagh.com
Fri Feb 16 17:58:44 CET 2007
Not sure if this solution/hack will work for you, but a quasi way to
reinitialize the interpreter is to clear the main dictionary to the original
- make a copy of the main dictionary upon initialization
- run your python script
- clear the main dictionary
- set the dictionary to the original copy.
object main_module (handle<> (borrowed (PyImport_AddModule
object dictionary = main_module.attr ("__dict__") ;
// copy the dictionary
PyObject* clean_dict = PyDict_Copy (dictionary.ptr()) ;
// run your python script.
// reset main dictonary
PyDict_Clear (dictionary.ptr()) ;
PuDict_Update (dictionary.ptr(), clean_dict) ;
Py_XDECREF (clean_dict) ;
Something like anyways. This could be a total hack, and I'm not sure it's
foolproof, but it at least resets the main dictionary so that it appears to
be a new session.
----- Original Message -----
From: "Podpruzhnikov Yuri" <ypodpruzhnikov at mcode.ru>
To: <c++-sig at python.org>
Sent: Thursday, February 15, 2007 7:56 AM
Subject: [C++-sig] PyFinalize Safety
> We embed Python to our project and use Boost.Python. Very much code had
> been already created.
> But great problem came to us: python interpreter must be reinitialized,
> but Boost.Python doesn't support "PyFinalize Safety"
> I see 2 decisions of the problem:
> 1) We delete Boost.Python from our project. But this will make extension
> of Python very difficult. :)
> 2) We write (or find) "PyFinalize Safety" of Boost.Python.
> I choose 2-nd decision till now. But if it is very difficult, I'll
> choose the 1-st way of solving the problem.
> I have a few questions to ask:
> - What is the difficulty of this problem to be solved?
> - Have anyone already written this?
> - If yes, could you give me code or advice at least?
> Sorry for my English.
> C++-sig mailing list
> C++-sig at python.org
More information about the Cplusplus-sig