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 <1568019088.84.0.443323623922.issue38062@roundup.psfhosted.org>
In-reply-to
Content
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
    False

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

    >>> clean1 == clean2
    True

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.
History
Date User Action Args
2019-09-09 08:51:28mark.dickinsonsetrecipients: + mark.dickinson
2019-09-09 08:51:28mark.dickinsonsetmessageid: <1568019088.84.0.443323623922.issue38062@roundup.psfhosted.org>
2019-09-09 08:51:28mark.dickinsonlinkissue38062 messages
2019-09-09 08:51:28mark.dickinsoncreate