473,473 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C Extended module init/cleanup

I'm extending Python with C, it seems as though initialization is easy
enough with an init<moduleName>() function that all C extended python
modules must provide that can serve as a sort of "module constructor".

Can C extended python modules provide any kind module destructor, so
that whenever the module is unloaded some cleanup is run?

Thanks,

carl
--

Carl J. Van Arsdall
cv*********@mvista.com
Build and Release
MontaVista Software

Jan 23 '06 #1
1 1772
> Can C extended python modules provide any kind module destructor, so
that whenever the module is unloaded some cleanup is run?

I've needed the same thing before but couldn't find it. AFAIK, the best
you can do is register an exit function that will be called when python
exits. Here is a sample code snippet:

//Called when python exits
void CleanupModule(void)
{
//Perform cleanup here
}
Then in your init<module> function add the following code:

//Register function to be called when python exits
Py_AtExit(CleanupModule);

-Farshid
Jan 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dylan Shell | last post by:
How do I register a clean up function for a module written in C? While I can find plenty of documentation for the "init<module_name>" function... I don't see a single reference on a...
3
by: Andrew Gregory | last post by:
I've written a Tkinter application (Windows) that uses the threading module, which I've reduced to the test case below (apologies if it's a bit long). Using the Queue module to pass messages the...
2
by: James S | last post by:
Hi, Basically I've been fighting with this code for a few days now and can't seem to work around this problem. Included is the output, the program I use to get this error and the source code for...
0
by: Brandon Craig Rhodes | last post by:
Python modules written in C are often written as single .c files (sometimes quite large) so that everything can be declared "static" except for the init<module>() function; and though the Extending...
5
by: nimdez | last post by:
Hi, I am working on an existing code base in which a lot of data displayed to the user is formatted in tables. Most tables are printed row-by-row using printf() with "%s" print conversion...
2
by: xenophon | last post by:
I am trying to format datetime output with an HTTP Module. Right now dates are displaying in US format like "MM/DD/YYYY 12:00:00". I want to change the output to "MM/DD/YYYY" if US or "DD.MM.YYYY"...
6
by: Tuvas | last post by:
I know this is probably a very simple question, but I am building a program that is now at about 2400 lines of code in the main module. I need to break it up, however, there are certain variables...
18
by: bearophileHUGS | last post by:
In few minutes I have just written this quite raw class, it lacks doctring (the same of the functions of the heapq module), it may contain bugs still, I haven't tested it much. It's just a simple...
3
by: cjt22 | last post by:
Hi I am new to Python (I have come from a large background of Java) and wondered if someone could explain to me how I can access variables stored in my main module to other functions within...
0
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...
1
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...
0
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...
0
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
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.