1 Apr 2000 02:55
A surprising case of cyclic trash
Tim Peters <tim_one <at> email.msn.com>
2000-04-01 00:55:54 GMT
2000-04-01 00:55:54 GMT
This comes (indirectly) from a user of my doctest.py, who noticed that
sometimes tempfiles created by his docstring tests got cleaned up (via
__del__), but other times not. Here's a hard-won self-contained program
illustrating the true cause:
class Critical:
count = 0
def __init__(self):
Critical.count = Critical.count + 1
self.id = Critical.count
print "acquiring Critical", self.id
def __del__(self):
print "releasing Critical", self.id
good = "temp = Critical()\n"
bad = "def f(): pass\n" + good
basedict = {"Critical": Critical}
for test in good, bad, good:
print "\nStarting test case:"
print test
exec compile(test, "<string>", "exec") in basedict.copy()
And here's output:
D:\Python>python misc\doccyc.py
Starting test case:
temp = Critical()
(Continue reading)
ciao - chris-and-the-undead-heresy
RSS Feed