[Jim Fulton] > Treating weakrefs with callbacks as reachable is a *big* change, though > in subtle ways. It sure appears to have "more consequences" than I guessed it would. > I agree that this is too big for 2.4, but I *do* think it should be > considered for 2.5. Me too. It ensures that a callback is never ignored unless a referent definitely outlives a weakref with that callback, even at the cost of resurrecting trash weakrefs (to make their callbacks safe to call). "Definitely outlives" is usually easy to talk about in CPython because of refcount lifetime semantics, but hard to make sense of operationally without refcount semantics. When they're both in cyclic trash, a weakref and its referent both become unreachable truly at the same instant. The approach so far has then been to say (in effect): Fine, then it's legitimate to impose any linear order on death, and if we say the weakref dies first, then there's no issue remaining -- just as in non-cyclic trash, when a weakref dies before its referent, the wr's callback will never be invoked. That's defensible but not compelling. I'm still not sure any other approach is compelling either. patch-finalizer effectly reverses the current approach, saying: Fine, then it's legitimate to impose any linear order on death, and if we say the referent dies first, then there's no issue remaining -- just as in non-cyclic trash, when the referent dies before its weakref, the wr's callback will be invoked(*). (*) Except we have to resurrect the weakref to make this possible, and that may also end up resurrecting the referent, and then neither actually goes away, and so the callback doesn't actually get invoked either (although it may get invoked later, if the user fiddles with the stuff in gc.garbage enough to make that possible). All I can say is that the callback better be damned important to justify all the extra pain <wink>. still-seeking-use-cases-ly y'rs - tim
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4