mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +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:
commit
2116b12da5
27 changed files with 315 additions and 209 deletions
|
@ -460,9 +460,10 @@ class Listener(object):
|
|||
'''
|
||||
Close the bound socket or named pipe of `self`.
|
||||
'''
|
||||
if self._listener is not None:
|
||||
self._listener.close()
|
||||
listener = self._listener
|
||||
if listener is not None:
|
||||
self._listener = None
|
||||
listener.close()
|
||||
|
||||
address = property(lambda self: self._listener._address)
|
||||
last_accepted = property(lambda self: self._listener._last_accepted)
|
||||
|
@ -594,9 +595,13 @@ class SocketListener(object):
|
|||
return Connection(s.detach())
|
||||
|
||||
def close(self):
|
||||
self._socket.close()
|
||||
if self._unlink is not None:
|
||||
self._unlink()
|
||||
try:
|
||||
self._socket.close()
|
||||
finally:
|
||||
unlink = self._unlink
|
||||
if unlink is not None:
|
||||
self._unlink = None
|
||||
unlink()
|
||||
|
||||
|
||||
def SocketClient(address):
|
||||
|
|
|
@ -130,9 +130,13 @@ class Queue(object):
|
|||
|
||||
def close(self):
|
||||
self._closed = True
|
||||
self._reader.close()
|
||||
if self._close:
|
||||
self._close()
|
||||
try:
|
||||
self._reader.close()
|
||||
finally:
|
||||
close = self._close
|
||||
if close:
|
||||
self._close = None
|
||||
close()
|
||||
|
||||
def join_thread(self):
|
||||
debug('Queue.join_thread()')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue