[Python-Dev] Unload a module written in C

Victor Stinner victor.stinner at haypocalc.com
Fri Mar 25 12:36:01 CET 2011


Le vendredi 25 mars 2011 à 21:14 +1000, Nick Coghlan a écrit :
> On Fri, Mar 25, 2011 at 8:14 PM, Victor Stinner
> <victor.stinner at haypocalc.com> wrote:
> > Le vendredi 25 mars 2011 à 07:59 +0100, "Martin v. Löwis" a écrit :
> >> > Is there a bug somewhere, or do I misunderstood something important?
> >>
> >> Module unloading is simply not implemented, and would be very difficult
> >> to implement.
> >
> > My problem is that if Python is embeded, my module will still be active
> > after Py_FinalizeEx(). For example, if it installed an handler for the
> > SIGSEGV signal: a segmentation fault will call the handler which will
> > try to get the interpreter state, but there is no more interpreter. I
> > don't know if it is a problem or not, but I would prefer to cleanup my
> > module on Py_FinalizeEx().
> 
> And registering your cleanup function with atexit() isn't enough? Or
> does that remove the handler too early?

atexit() is too late: when Python is embeded, Py_Finalize() may be
called a long time before the program does really finish.

Well, I never embeded Python in another program, but it looks like some
people do initialize/finalize Python more than once:

http://bugs.python.org/issue11321
"9th import of module _pickle always crashes"

In this issue, Python is initialized/finalized 20 times.

Victor



More information about the Python-Dev mailing list