[C++-sig] Py_Finalize() crashes when PyImport_Import() fails

SrMandrake ElMago srmandrake at yahoo.com
Mon Aug 25 05:29:04 CEST 2008


That was it! Thanks Stefan...
If ever in Costa Rica...email me. I'll buy u a beer! :-D
Pura Vida (Y)



----- Original Message ----
From: Stefan Seefeld <seefeld at sympatico.ca>
To: Development of Python/C++ integration <c++-sig at python.org>
Sent: Sunday, August 24, 2008 8:31:42 PM
Subject: Re: [C++-sig] Py_Finalize() crashes when PyImport_Import() fails

SrMandrake ElMago wrote:
>
> Exception exceptions.ImportError: 'No module named test_11' in 
> 'garbage collection' ignored
> Fatal Python error: unexpected exception during garbage collection
The Python runtime may expect you to call handle Python exceptions 
explicitely, prior to finalizing.

> if ( !pModule )
>
> {
>

If you got 0 here, Python has set an exception. Before moving on you 
should handle it, for example by explicitely clearing it:

PyErr_Clear();

>    std::cout << "Unable to open script " << s << std::endl;
>
>    getchar ();
>
> }
>
>  
>
> Py_XDECREF( pModule );
>
> Py_XDECREF( pName );
>
>  
>
> Py_Finalize ();
>

With the above addition, the Python runtime should finalize fine.

HTH,
      Stefan


-- 

      ...ich hab' noch einen Koffer in Berlin...

_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080824/3cb5b9af/attachment.htm>


More information about the Cplusplus-sig mailing list