unloading extension library

Bill Pursell bill.pursell at gmail.com
Wed Oct 18 21:23:24 CEST 2006


Bill Pursell wrote:
> I've got a simple extension module that contains two functions:
> void hi(void) __attribute__((constructor));
> void hi(void) { printf("Hi!\n");}
> void bye(void) __attribute__((destructor));
> void bye(void) { printf("Bye!\n");}
>
>
> When I run in the interpreter:
>
> >>> import spam
> Hi!
> >>> del spam
> >>>
>
> Notice that the destructor isn't called.  How can I force python
> to dlclose() the library and ensure that my destructors get called?
>

There is something about my google-fu that only allows me to
find things 25 seconds after I post....

>>> del sys.modules["spam"]
>>> del spam

Should remove all the references, but I still don't want to wait for
garbage collection.  I need to be sure that the dlclose() happens
and the destructors are called.  Can I do that? (without relying
on ctypes, preferrably.)

--
Bill Pursell




More information about the Python-list mailing list