C Extended module init/cleanup

  • Thread starter Carl J. Van Arsdall
  • Start date
C

Carl J. Van Arsdall

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
(e-mail address removed)
Build and Release
MontaVista Software
 
F

Farshid Lashkari

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top