WeakRef
"Mark Hahn" <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
I implemented a weak reference object in build 671. Since it requires notification of when an object is deleted, it was easy to add a feature to allow a callback when the reference object is read, written or deleted. This would be useful for debugging and maybe other situations. The delete callback is an external alternative to the del_ method also. The methods are... weakref = WeakRef(obj) WeakRef.str_() => <Prototype:WeakRef> weakref.str_() => <WeakRef:obj.str_()> obj = weakref.ref() # throws exception if obj doesn't exist anymore weakref.exists?() The notify feature has these constants to indicate whether you want notification on a read access, write access, or deletion of the obj. WeakRef.READ WeakRef.WRITE WeakRef.DELETE The notify method sets up a callback (func) with an optional param for the callback and flags to tell under which circumstances to do the callback. If you call this with flags = 0 then the callback will be removed. WeakRef.notify(func, param=None, flags = WeakRef.WRITE | WeakRef.DELETE) weakref.flags() Comments?