diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-10 10:29:28 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-10 10:29:28 (GMT) |
commit | 2116b12da59f77358cc539b90f58a3cdea43c2fd (patch) | |
tree | 693d26652b1dbf8b2ac058c5725f9726c3d14a0b /Lib/xmlrpc | |
parent | fcbf8f3e3d46eb023dd9a3954c6f9ed9a533d427 (diff) | |
parent | 7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd (diff) | |
download | cpython-2116b12da59f77358cc539b90f58a3cdea43c2fd.zip cpython-2116b12da59f77358cc539b90f58a3cdea43c2fd.tar.gz cpython-2116b12da59f77358cc539b90f58a3cdea43c2fd.tar.bz2 |
Issue #23865: close() methods in multiple modules now are idempotent and more
robust at shutdown. If needs to release multiple resources, they are released
even if errors are occured.
Diffstat (limited to 'Lib/xmlrpc')
-rw-r--r-- | Lib/xmlrpc/client.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index da089a2..acb8142 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -438,8 +438,13 @@ class ExpatParser: self._parser.Parse(data, 0) def close(self): - self._parser.Parse("", 1) # end of data - del self._target, self._parser # get rid of circular references + try: + parser = self._parser + except AttributeError: + pass + else: + del self._target, self._parser # get rid of circular references + parser.Parse(b"", True) # end of data # -------------------------------------------------------------------- # XML-RPC marshalling and unmarshalling code @@ -1065,8 +1070,10 @@ class GzipDecodedResponse(gzip.GzipFile if gzip else object): gzip.GzipFile.__init__(self, mode="rb", fileobj=self.io) def close(self): - gzip.GzipFile.close(self) - self.io.close() + try: + gzip.GzipFile.close(self) + finally: + self.io.close() # -------------------------------------------------------------------- @@ -1221,9 +1228,10 @@ class Transport: # Used in the event of socket errors. # def close(self): - if self._connection[1]: - self._connection[1].close() + host, connection = self._connection + if connection: self._connection = (None, None) + connection.close() ## # Send HTTP request. |