[C++-sig] PyFinalize Safety

Podpruzhnikov Yuri ypodpruzhnikov at mcode.ru
Mon Feb 19 12:29:50 CET 2007


Accept my apologies for my wrong describing the problem, in my previous
post.
I'll try to describe it in another way.

The interpreter is completely embedded into our program, that's why
interpreter is only finalized during program termination.
And our program will work permanently for 24 hours a day, 7 days a week.
The program executes Python scripts from time to time.
Everything described above makes next problems:
1) It increases amount of memory allocated for the program, after every
script execution:
        +  Executed scripts always stays in memory as modules.
        +  If any exceptions are raised some local context objects
doesn't delete from memory, even if used garbage collection.
2) Improper scripts changing data in sys-module (or any other common
using modules) may influence on next scripts execution.

In that way the simplest decision of this problem is periodical runtime
reinitialization of Python interpreter.

"__main__"-dictionary cleaning solves only the first part of problem,
but it doesn't solve the other one.

The general problem of reinitialization of Python (with Boost.Python) is
next:
After calling PyFinalize and then PyInitialize and trying to import
extension C++ modules many errors occur. The same problem is described
in http://mail.python.org/pipermail/c++-sig/2004-April/007147.html.




----- 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"
> (http://www.boost.org/libs/python/todo.html#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?
>



More information about the Cplusplus-sig mailing list