[New-bugs-announce] [issue44301] Is there a way to provide destructor for module written using C API?

Azat Ibrakov report at bugs.python.org
Thu Jun 3 12:13:29 EDT 2021


New submission from Azat Ibrakov <azatibrakov at gmail.com>:

I'm reimplementing `fractions.Fraction` class using C API (https://github.com/lycantropos/cfractions).

And the problem is that I want to use `numbers.Rational` interface in my type checks to add support for user-defined rational numbers.

I see how it's done for `decimal.Decimal` class:
https://github.com/python/cpython/blob/142e5c5445c019542246d93fe2f9e195d3131686/Modules/_decimal/_decimal.c#L2916
but the problem is: I don't see when/where we call `Py_DECREF(Rational)`, so it looks like this class will not be "freed" until the  end of the program.

So my question is: is there any way to define some function which will be called once module is not used?

----------
components: C API
messages: 395012
nosy: lycantropos
priority: normal
severity: normal
status: open
title: Is there a way to provide destructor for module written using C API?
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44301>
_______________________________________


More information about the New-bugs-announce mailing list