From: Giampaolo Rodola' Date: Tue, 9 Apr 2013 15:21:25 +0000 (+0200) Subject: Do not raise exception on close() on account of socket attribute still being None: X-Git-Tag: v3.4.0a1~1002 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a4c377cde9b010f6bee5e5e0a15e8545228d31e2;p=python Do not raise exception on close() on account of socket attribute still being None: >>> import asyncore >>> d = asyncore.dispatcher() >>> d.close() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.4/asyncore.py", line 401, in close self.socket.close() AttributeError: 'NoneType' object has no attribute 'close' >>> --- diff --git a/Lib/asyncore.py b/Lib/asyncore.py index f1466436d1..75481ddde0 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -397,11 +397,12 @@ class dispatcher: self.accepting = False self.connecting = False self.del_channel() - try: - self.socket.close() - except OSError as why: - if why.args[0] not in (ENOTCONN, EBADF): - raise + if self.socket is not None: + try: + self.socket.close() + except OSError as why: + if why.args[0] not in (ENOTCONN, EBADF): + raise # cheap inheritance, used to pass all other attribute # references to the underlying socket object.