[Stackless] uthreads and reference counting
Mike C. Fletcher
mcfletch at home.com
Mon Mar 12 03:16:49 CET 2001
On my machine (using stackless 1.5.4+), I get this output:
p:\>uthreadleak01.py
0
1
2
3
4
end of starter(), refcount= 1
del A() called
Possibly this is a Stackless 2.0 problem?
Enjoy,
Mike
-----Original Message-----
From: Bernd Rinn [mailto:Bernd.Rinn at epost.de]
Sent: Sunday, March 11, 2001 1:51 PM
To: Stackless Python mailinglist
Subject: [Stackless] uthreads and reference counting
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
_______________________________________________
Stackless mailing list
Stackless at starship.python.net
http://starship.python.net/mailman/listinfo/stackless
More information about the Stackless
mailing list