Message70819
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") |
|
Date |
User |
Action |
Args |
2008-08-07 12:55:58 | ocean-city | set | recipients:
+ ocean-city, loewis |
2008-08-07 12:55:57 | ocean-city | set | messageid: <1218113757.99.0.15519174758.issue3515@psf.upfronthosting.co.za> |
2008-08-07 12:55:41 | ocean-city | link | issue3515 messages |
2008-08-07 12:55:40 | ocean-city | create | |
|