[Stackless] uthreads and reference counting

Bernd Rinn Bernd.Rinn at epost.de
Sun Mar 11 19:50:33 CET 2001


Hi,

when passing python objects to microthreads, the memory need of the
python program is increasing with time. It seems that microthreads
have a problem with reference counting. I have written a small sample
program 'refcount.py' that demonstrates the problem: an object 'a' is
passed to 5 microthreads (function 'f'). When the microthreads are
finished, the reference count is 4 (while it should be 1). The object
'a' is never finalized (the message "del A() called" is never printed
out). This is the program:

--- refcount.py ---------------------------------------------------------
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)
    uthread.wait(0.1) # wait till threads are finished
    print "end of starter(), refcount=", sys.getrefcount(a)-1

uthread.new(starter)
uthread.run()
------------------------------------------------------------------------

and here is the output:

------------------------------------------------------------------------
$ python refcount.py
0
1
2
3
4
end of starter(), refcount= 4
------------------------------------------------------------------------

The refcount is increasing when the number of threads is increased.

It this problem already known? Is there a workaround?

Cheers,

Bernd
-- 
Bernd Rinn
Fakultät für Physik
Universität Konstanz

Tel. 07531/88-3812, 
e-mail: Bernd.Rinn at uni-konstanz.de
PGP-Fingerprint: 1F AC 31 64 FF EF A9 67  6E 0D 4C 26 0B E7 ED 5C
_______________________________________________
Stackless mailing list
Stackless at starship.python.net
http://starship.python.net/mailman/listinfo/stackless



More information about the Stackless mailing list