This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients mark.dickinson
Date 2019-09-09.08:51:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Suppose I have a class that looks like this:

    class A:
        def cleanup(self):
            print("Doing essential cleanup")

and on an instance `a = A()`, I do: `atexit.register(a.cleanup)`.

Then it's not obvious from the documentation that an `atexit.unregister(a.cleanup)` will successfully undo the effect of the reigster call: the second `a.cleanup` is a different object from the first:

    >>> a = A()
    >>> clean1 = a.cleanup
    >>> clean2 = a.cleanup
    >>> clean1 is clean2

Luckily, though the two bound methods are different objects, they're equal:

    >>> clean1 == clean2

and from looking at the source, it's apparent that `atexit.unregister` compares by equality rather than identity, so everything works.

It would be good to add a sentence to the documentation for `atexit.unregister` to clarify that this can be expected to work.
Date User Action Args
2019-09-09 08:51:28mark.dickinsonsetrecipients: + mark.dickinson
2019-09-09 08:51:28mark.dickinsonsetmessageid: <>
2019-09-09 08:51:28mark.dickinsonlinkissue38062 messages
2019-09-09 08:51:28mark.dickinsoncreate