]> granicus.if.org Git - python/commitdiff
I saw errors from _fileobject.__del__ about missing self._sock. This
authorGuido van Rossum <guido@python.org>
Thu, 29 May 2003 14:36:57 +0000 (14:36 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 29 May 2003 14:36:57 +0000 (14:36 +0000)
can happen if __init__ doesn't complete.  Fix it by adding a
try/except to __del__.

Lib/socket.py

index 9598f99fc5fee32e348b7681b3c3cd4ae5fc5c6f..b95c372da5f3301fee90853781a5593ab0d18bb9 100644 (file)
@@ -232,7 +232,11 @@ class _fileobject(object):
             self._sock = None
 
     def __del__(self):
-        self.close()
+        try:
+            self.close()
+        except:
+            # close() may fail if __init__ didn't complete
+            pass
 
     def flush(self):
         if self._wbuf: