Document listener lifetimes
- Dominant language
- Python
- Stars
- 462
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Description
When attaching a trait change listener dynamically to a `HasTraits` object, the lifetime of the listener changes depending on whether it's a bound method or a function.
For a bound method listener, the notify wrapper for that listener keeps a weak reference to the object that the method is bound to (the ``__self__`` attribute of the listener), so that when the object is deleted, the listener no longer fires.
For a function listener, the notify wrapper keeps a regular reference to the listener function, so the function continues to fire after other references to it have been deleted. In other words, it's tied to the lifetime of the object to which the listener is attached.
The two behaviours are somewhat inconsistent, but it would be very difficult to change them without breaking code (there are almost certainly lambda functions acting as listeners out there somewhere). But we can and should make sure that the lifetimes are properly documented.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.