By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,002 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,002 IT Pros & Developers. It's quick & easy.

unloading extension library

P: n/a
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?
--
Bill Pursell

Oct 18 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

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

Oct 18 '06 #2

P: n/a
Bill Pursell wrote:
>>>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.)
in general, no. Python's not C++; you cannot rely on the garbage
collector to release resources at a given time (or to release them at
all, for that matter).

if you want to tear down an object or a module in a reliable fashion,
you need to provide an API for that purpose.

</F>

Oct 18 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.