[issue3515] refcount gc bug?
Hirokazu Yamamoto
report at bugs.python.org
Thu Aug 7 14:55:57 CEST 2008
Hirokazu Yamamoto <ocean-city at users.sourceforge.net> added the comment:
Hmm, when exception occurs in some frame, its reference will be
retained even after exiting function? Indeed, extra
exception fixed problem.
import os
def foo():
io = open("a.txt", "w")
raise RuntimeError()
try:
foo()
except:
pass
try:
raise RuntimeError()
except:
pass
os.remove("a.txt") # fine
But still I'm little confused why this code prints "del".
class A:
def __del__(self):
print "del"
def foo():
a = A()
raise RuntimeError()
try:
foo()
except:
pass
I found this behavior when investigating issue3210. When
Lib/subprocess.py (814)'s CreateProcess() raises exception,
p2cread will be freed by refcount GC, it never happen before
os.remove(). And this error is also fixed by same hack.
import subprocess, os
file = open("filename", "w")
try:
proc = subprocess.Popen("nosuchprogram", stdout=file)
except OSError:
pass
try:
raise RuntimeError() # hack
except:
pass
file.close()
os.remove("filename")
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3515>
_______________________________________
More information about the Python-bugs-list
mailing list