mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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.
This commit is contained in:
parent
842f00e725
commit
7e7a3dba5f
27 changed files with 299 additions and 197 deletions
|
@ -211,17 +211,19 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
|
|||
self._err_handler.fatalError(exc)
|
||||
|
||||
def close(self):
|
||||
if self._entity_stack:
|
||||
if self._entity_stack or self._parser is None:
|
||||
# If we are completing an external entity, do nothing here
|
||||
return
|
||||
self.feed("", isFinal = 1)
|
||||
self._cont_handler.endDocument()
|
||||
self._parsing = 0
|
||||
# break cycle created by expat handlers pointing to our methods
|
||||
self._parser = None
|
||||
bs = self._source.getByteStream()
|
||||
if bs is not None:
|
||||
bs.close()
|
||||
try:
|
||||
self.feed("", isFinal = 1)
|
||||
self._cont_handler.endDocument()
|
||||
finally:
|
||||
self._parsing = 0
|
||||
# break cycle created by expat handlers pointing to our methods
|
||||
self._parser = None
|
||||
bs = self._source.getByteStream()
|
||||
if bs is not None:
|
||||
bs.close()
|
||||
|
||||
def _reset_cont_handler(self):
|
||||
self._parser.ProcessingInstructionHandler = \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue