[Stackless] uthreads and reference counting

Changjune Kim junaftnoon at yahoo.com
Mon Mar 12 05:50:25 CET 2001

I found quite an interesting point:

If we add a few lines to the original code given by Rinn as:

import sys, uthread

class A:
    def __del__(self): print "del A() called"

def f(a, i): print i

def starter():
    a = A()
    for i in xrange(5): uthread.new(f, a, i)
    print "ends of starter(), refcount=", sys.getrefcount(a)-1

for i in range(4): pass

This results out "refcount =1" with "del A()..."
However, if I change the magic number for the loop from 4 to 3,5,6,7,8,9 and
so on, the result varies. Sometimes "refcount=4", or "refcount=2", sometimes
with "del A().." or without even when "refcount=1".

Maybe it has something to do with opcodes counting and GC...

Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

Stackless mailing list
Stackless at starship.python.net

More information about the Stackless mailing list