[Tutor] exit handler for C extension module

Stefan Behnel stefan_ml at behnel.de
Mon Jan 18 11:28:20 CET 2010


Shuying Wang, 18.01.2010 08:58:
> I found what I was after, right after I posted to this list. It's
> Py_AtExit. I'm accessing an old, unsupported database using it's C
> API.

I didn't write the respective code in Cython, but there's a comment next to
it saying

    /* Don't use Py_AtExit because that has a 32-call limit
     * and is called after python finalization. */

So Py_AtExit() may or may not be what you are looking for.

Also note that Py3 has a C-API mechanism for safely cleaning up (and
potentially unloading) modules, which likely is what you are looking for
anyway.


> I've tried using Cython but found it hard to get my head around
> and I'm finding it somewhat easier to just write by hand.

Personally, I find it a matter of developer time (basically "why write C
when you can write Python?"), but your mileage may vary.

Stefan



More information about the Tutor mailing list