httppeer: make __del__ access to self.urlopener more safe stable
authorMads Kiilerich <madski@unity3d.com>
Mon, 31 Oct 2016 13:43:48 +0100
branchstable
changeset 30241 cac4ca036dff
parent 30240 8237c3359db5
child 30242 389cbfe63586
httppeer: make __del__ access to self.urlopener more safe Some errors could in some cases show unfortunate scary and confusing warnings from the httppeer delstructors: abort: nodename nor servname provided, or not known Exception AttributeError: "'httpspeer' object has no attribute 'urlopener'" in <bound method httpspeer.__del__ of <mercurial.httppeer.httpspeer object at 0x106e1f5d0>> ignored``` To mute that, take 7b15dd9125b3 to the next level and use getattr in __del__.
mercurial/httppeer.py
--- a/mercurial/httppeer.py	Sun Oct 30 06:15:09 2016 +0900
+++ b/mercurial/httppeer.py	Mon Oct 31 13:43:48 2016 +0100
@@ -63,8 +63,9 @@
         self.requestbuilder = urlreq.request
 
     def __del__(self):
-        if self.urlopener:
-            for h in self.urlopener.handlers:
+        urlopener = getattr(self, 'urlopener', None)
+        if urlopener:
+            for h in urlopener.handlers:
                 h.close()
                 getattr(h, "close_all", lambda : None)()