Hirokazu Yamamoto <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> <http://bugs.python.org/issue3515> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com