This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ocean-city
Recipients loewis, ocean-city
Date 2008-08-07.12:55:40
SpamBayes Score 2.073205e-05
Marked as misclassified No
Message-id <1218113757.99.0.15519174758.issue3515@psf.upfronthosting.co.za>
In-reply-to
Content
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")
History
Date User Action Args
2008-08-07 12:55:58ocean-citysetrecipients: + ocean-city, loewis
2008-08-07 12:55:57ocean-citysetmessageid: <1218113757.99.0.15519174758.issue3515@psf.upfronthosting.co.za>
2008-08-07 12:55:41ocean-citylinkissue3515 messages
2008-08-07 12:55:40ocean-citycreate