From: Stefan Behnel on
Mr.M, 30.01.2010 14:24:
> Could I allocate my resources in a "static" object linked to my module?

Sure, but you will have to let CPython know about it so that it can see
that the reference is only held by the module that it is cleaning up.
Otherwise it can't collect the reference. This works easily in Py3 but not
in Py2.

In Cython, you would just write

cdef ResourceKeeper resource_keeper = ResourceKeeper()

at the module level and let Cython generate the cleanup code for it. In C,
you have to implement an atexit function and decref the resource object
either there or in the module cleanup function of Py3.


> (without publishing
> the type of that object so that I can't instantiate another one)

Note that there is the type() builtin function which returns the type given
an instance. So you can't hide the type.

Stefan
From: Mr.M on
Stefan Behnel ha scritto:
> Note that there is the type() builtin function which returns the type given
> an instance. So you can't hide the type.

Argh! Yes, you are right.

So I'd better have a look to Cython, right?

L-