Message351363
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. |
|
Date |
User |
Action |
Args |
2019-09-09 08:51:28 | mark.dickinson | set | recipients:
+ mark.dickinson |
2019-09-09 08:51:28 | mark.dickinson | set | messageid: <1568019088.84.0.443323623922.issue38062@roundup.psfhosted.org> |
2019-09-09 08:51:28 | mark.dickinson | link | issue38062 messages |
2019-09-09 08:51:28 | mark.dickinson | create | |
|