473,657 Members | 2,535 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 2051

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
4615
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 implemented some Qt classes (not completly) like QApplication, QObject, QWidget, Qlabel, QLineEdit and QGrid just to test some very simple application. The mecanisme of the SLOT and SIGNAL is working but only for the existing slot and signal.
2
1744
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 extension. Is there a 3rd party library of extension helpers that assist in representing c-types between Python and c? Are there any tips and tricks? Here are some specific scenarios I am running into. 1) Refrencing and derefrencing: For...
2
1803
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, which calls another function in another library, which calls another function, which calls fmod from the standard C math library. All of these are shared libraries on Linux (x86 Gentoo 2.6.9). In other words, the calling looks like this: Python...
9
4423
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++ program -- DSN710.SDSNSAMP(DSN8DLPL) to use for this purpose. I'm wondering if anyone out there has a COBOL equivalent to this as I do not have a C++ compiler?
4
6020
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 extension. The code like this: public string HelloWorld() { return "Hello World.";
6
1607
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 seems realy easy to use this library: - I inherited from ContextMenuHandlerBase - I made the assembly COM-visible - Registered for COM interop
5
2024
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 to call GC_INIT() at the start of the program that uses the library. Now I want to encapsulate the library as a CPython extension. The question is really is that possible? And will there be conflicts between the boehm-gc and Python memory...
5
7948
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, it can open the file. However, when I run Php5 I (now) get this error message: "Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?" This is new. Last time I messed with this, I merely got:
6
4210
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: extension_dir = "/correct/verified/path/to/extension/dir/" extension=imagick.so Apache will not restart if both those lines are present in php.ini
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5642
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.