Reference Tracking

Matt Bergin spam at mattbergin.co.uk
Mon Apr 14 07:28:17 EDT 2003


Alex Martelli wrote:
> Matt Bergin wrote:
>    ...
>>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).

Just out of interest, when I run a very simple script, i.e.

import sys
a=1
print sys.getrefcount(a)

Why is the refcount of a so high (50 from the command line)? Where are 
these references lurking? Should I check be checking for changes in the 
refcount of an object rather than its absolute value?

-- 
Matt Bergin





More information about the Python-list mailing list