Reference Tracking

Alex Martelli aleax at aleax.it
Sun Apr 13 18:02:07 EDT 2003


Matt Bergin wrote:
   ...
>> You can try to avoid the periodic scanning overhead by using a
>> tricky __del__, or a non-tricky __del__ or weak-reference callback
>> for some object that's "packed together with" the object you give
>> out (keeping the latter alive in a per-class container anyway).  A
>> radically different and far cleaner approach would be to specify
>> a way (e.g. a method) for the using-code to say "I'm finished with
>> this object, reuse it freely from now on" -- no black magic at all
>> (of course, perhaps marginally smaller convenience for the using
>> code, but it's not all that bad to ensure a finalization method
>> gets explicitly called, IMHO).
> 
> I'm just worried that if an exception occurs in a thread then the cursor
> will never be returned, using the 'no black magic' method which appeals
> to me the most. Could I prevent this by careful use of try: finally?

Yes.  And you can *in addition* keep the cursors you've handed out
in a list and ALSO periodically do the scan checking refcounts just
to help you debug user threads that aren't returning cursors properly
(or use other tricks as above but for debugging-help rather than
functional purposes).


Alex





More information about the Python-list mailing list