Py_Finalize Crashes in after PyRun_File

mk mrunalinikulkarni at yahoo.com
Mon Oct 7 04:18:40 EDT 2002


Jon.Kare.hellan at uninett.no (Jon Kåre Hellan) wrote in message news:<ter8f6d12h.fsf at persaunet.uninett.no>...
> mrunalinikulkarni at yahoo.com (mk) writes:
> 
> > I run a python script which contains objects of classes declared in an
> > extension module.
> > 
> > the code that i use to execute the script file is as follows-
> > 
> > if (!Py_IsInitialized()) Py_Initialize();
>  ..
> > 	Py_Finalize();
> > 
> > This code gets executed from a menu item click of my VC++ 6.0
> > application. the first time i execute it the script gets executed
> > fine. but the second time i execute the code it crashes at PyRun_File
> > statement. This does not happen if i comment Py_Finalize in the above
> > code. Then the code can be executed repetitively without a crash.
> 
> You don't say, but my guess is that Py_Initialize is a static
> variable. Changing it to FALSE when you call Py_Finalize probably
> fixes this. On the other hand, do you really need Py_Finalize?
> 
> Regards
> 
> Jon Kåre


Actually I need to call the Py_Initialize and Py_finalize withtin the
menu handler of my vc application as i do not want to load interpreter
unless the Run script menu was clicked.Also i do not want to retain it
after i am done with the execution of the script. My VC application
does not need python to be running for any other feature.

Also as mentioned in the original message my script contains foll.
code

p=hit.printer() ->printer class defined in extention module hit.

if(p.start("list")):
        p.somememberfunc()   ->attributerror if the function not
defined or missplelt in the script.
	p.end()


If the script executes without an error, the printer object gets
destroyed fine.
But if as above, an error occurrs, the destructor of the printer
object will be called only when I close my VC app. ,if i call
Py_Finalize in exitinstance of the VC App. If, Py_Finalize is called
in the menu handler itself, the destruction will happen immediately
after the script runs into an error.

I would appreciate if you could write in detail about the solution
suggested earlier to make Py_Finalize() remain in the Menu Handler.

Ofcourse any other solution available for my problem, will be
appreciated.

Thanks,
MK



More information about the Python-list mailing list