473,505 Members | 13,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unloading extension library

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
2 2046

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4608
by: Gyger | last post by:
Hello, Three weeks ago, I have started to develop a binding extension for Qt and PHP 5. Now, I can display a dialog box containing some widgets like label, buttons and edit line. I have just...
2
1737
by: Letbetter, Jason | last post by:
I'm creating Python extensions for several c/c++ components. I'm using swig to create the extensions. The biggest challenge so far is working with the c args between Python and the Python...
2
1788
by: Lonnie Princehouse | last post by:
I've been trying to debug this for two days now, and it's a longshot but I'm hoping that someone here might recognize a solution. I've got a C extension which calls a function in a C library,...
9
4411
by: Rom Marshall | last post by:
Hi. Once a LOB size goes beyond 32KB in size, I'm not able to use the LOAD utility to unload the data off the tables for DB2 7.1 on OS/390. Instead, the documentation refers to a sample C++...
4
6005
by: pepcag | last post by:
I used http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconalteringsoapmessageusingsoapextensions.asp as a template to create a very simple web method with soap...
6
1598
by: Pieter | last post by:
Hi, I'm trying to use the Edanmo Shell Extension Library (http://www.mvps.org/emorcillo/en/code/shell/shellextensions.shtml) to make a Context Menu in the Windows Explorer with VB.NET 2005. It...
5
2016
by: malkarouri | last post by:
Hi everyone, Is it possible to write a Python extension that uses the Boehm garbage collector? I have a C library written that makes use of boehm-gc for memory management. To use that, I have...
5
7923
by: Chuck Anderson | last post by:
I run Apache 2.0.55, and Php (both 4.4.1 and 5.2.5) on my home PC (Windows XP). One of the scripts that I run daily needs to access a secure URL (https://..............). When I am running Php4,...
6
4203
by: tommybiegs | last post by:
I'm having a weird problem. I can't seem to force php to load an extension using php.ini, but it loads perfectly if I use dl() at the beginning of a test script. In php.ini I've got: ...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.