[Python-Dev] Silencing IO errors on del/dealloc?

Antoine Pitrou solipsis at pitrou.net
Sun Feb 22 20:32:32 CET 2009


Guido van Rossum <guido <at> python.org> writes:
> 
> OTOH the is a much larger category of false positives, where a close()
> call raise an exception for some spurious reason (see the quoted
> comment) but no harm is done; in the past the tracebacks printed for
> __del__ by default have caused nothing but confuse users (who think
> something is seriously wrong but have no way to debug it).
> 
> The svn history of those lines may have more pointers.

Well this code dates back to the first checkin in the py3k branch. Apparently
the old p3yk branch is not there anymore...

I understand the missing globals on shutdown problem, but the error may also be
a legitimate programming error, where a close() implementation fails for
whatever reason. At least displaying the error may encourage the programmer to
strengthen his implementation.

How about the following compromise:

    try:
        closed = self.closed
    except:
        # Object is in an unusable state, don't attempt anything
        pass
    else:
        if not closed:
            self.close()

Regards

Antoine.




More information about the Python-Dev mailing list