C Extended module init/cleanup

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carl J. Van Arsdall

    #1

    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
    cvanarsdall@mvi sta.com
    Build and Release
    MontaVista Software

  • Farshid Lashkari

    #2
    Re: C Extended module init/cleanup

    > Can C extended python modules provide any kind module destructor, so[color=blue]
    > that whenever the module is unloaded some cleanup is run?[/color]


    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(v oid)
    {
    //Perform cleanup here
    }


    Then in your init<module> function add the following code:

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

    -Farshid

    Comment

    Working...