cpython: e826940911c8 (original) (raw)

Mercurial > cpython

changeset 95518:e826940911c8 3.4

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. [#23865]

Serhiy Storchaka storchaka@gmail.com
date Fri, 10 Apr 2015 13:24:41 +0300
parents e40f5ef53819
children 4ddec11b5faf 5b728310edac d080f5ecdcd3
files Lib/aifc.py Lib/binhex.py Lib/chunk.py Lib/dbm/dumb.py Lib/distutils/text_file.py Lib/fileinput.py Lib/ftplib.py Lib/gzip.py Lib/http/client.py Lib/logging/__init__.py Lib/logging/handlers.py Lib/mailbox.py Lib/multiprocessing/connection.py Lib/multiprocessing/queues.py Lib/poplib.py Lib/selectors.py Lib/shelve.py Lib/smtplib.py Lib/sunau.py Lib/tarfile.py Lib/telnetlib.py Lib/tempfile.py Lib/urllib/response.py Lib/wave.py Lib/xml/sax/expatreader.py Lib/xmlrpc/client.py Misc/NEWS
diffstat 27 files changed, 299 insertions(+), 197 deletions(-)[+] [-] Lib/aifc.py 5 Lib/binhex.py 42 Lib/chunk.py 6 Lib/dbm/dumb.py 6 Lib/distutils/text_file.py 3 Lib/fileinput.py 40 Lib/ftplib.py 15 Lib/gzip.py 26 Lib/http/client.py 24 Lib/logging/__init__.py 21 Lib/logging/handlers.py 23 Lib/mailbox.py 12 Lib/multiprocessing/connection.py 15 Lib/multiprocessing/queues.py 10 Lib/poplib.py 29 Lib/selectors.py 12 Lib/shelve.py 24 Lib/smtplib.py 16 Lib/sunau.py 13 Lib/tarfile.py 61 Lib/telnetlib.py 5 Lib/tempfile.py 8 Lib/urllib/response.py 14 Lib/wave.py 22 Lib/xml/sax/expatreader.py 20 Lib/xmlrpc/client.py 20 Misc/NEWS 4

line wrap: on

line diff

--- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -356,7 +356,10 @@ class Aifc_read: self._soundpos = 0 def close(self):

def tell(self): return self._soundpos

--- a/Lib/binhex.py +++ b/Lib/binhex.py @@ -32,7 +32,8 @@ class Error(Exception): pass

States (what have we written)

-[_DID_HEADER, _DID_DATA, _DID_RSRC] = range(3) +_DID_HEADER = 0 +_DID_DATA = 1

Various constants

REASONABLY_LARGE = 32768 # Minimal amount we pass the rle-coder @@ -213,16 +214,21 @@ class BinHex: self._write(data) def close(self):

def binhex(inp, out): """binhex(infilename, outfilename): create binhex-encoded copy of a file""" @@ -436,11 +442,15 @@ class HexBin: return self._read(n) def close(self):

def hexbin(inp, out): """hexbin(infilename, outfilename) - Decode binhexed file"""

--- a/Lib/chunk.py +++ b/Lib/chunk.py @@ -85,8 +85,10 @@ class Chunk: def close(self): if not self.closed:

def isatty(self): if self.closed:

--- a/Lib/dbm/dumb.py +++ b/Lib/dbm/dumb.py @@ -248,8 +248,10 @@ class _Database(collections.MutableMappi raise error('DBM object has already been closed') from None def close(self):

del = close

--- a/Lib/distutils/text_file.py +++ b/Lib/distutils/text_file.py @@ -118,10 +118,11 @@ class TextFile: def close(self): """Close the current file and forget everything we know about it (filename, current line number)."""

def gen_error(self, msg, line=None): outmsg = []

--- a/Lib/fileinput.py +++ b/Lib/fileinput.py @@ -238,8 +238,10 @@ class FileInput: self.close() def close(self):

def enter(self): return self @@ -281,23 +283,25 @@ class FileInput: output = self._output self._output = 0

-

-

def readline(self): try:

--- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -667,11 +667,16 @@ class FTP: def close(self): '''Close the connection without assuming anything about it.'''

try: import ssl

--- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -500,19 +500,21 @@ class GzipFile(io.BufferedIOBase): return self.fileobj is None def close(self):

def flush(self,zlib_mode=zlib.Z_SYNC_FLUSH): self._check_closed()

--- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -492,9 +492,11 @@ class HTTPResponse(io.RawIOBase): fp.close() def close(self):

# These implementations are for the benefit of io.BufferedReader. @@ -873,13 +875,17 @@ class HTTPConnection: def close(self): """Close the connection to the HTTP server."""

def send(self, data): """Send `data' to the server.

--- a/Lib/logging/init.py +++ b/Lib/logging/init.py @@ -1011,14 +1011,19 @@ class FileHandler(StreamHandler): """ self.acquire() try:

--- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -627,9 +627,10 @@ class SocketHandler(logging.Handler): """ self.acquire() try:

@@ -1213,8 +1214,10 @@ class BufferingHandler(logging.Handler): This version just flushes and chains to the parent class' close(). """

class MemoryHandler(BufferingHandler): """ @@ -1268,13 +1271,15 @@ class MemoryHandler(BufferingHandler): """ Flush, set the target to None and lose the buffer. """

class QueueHandler(logging.Handler):

--- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -722,10 +722,14 @@ class _singlefileMailbox(Mailbox): def close(self): """Flush and close the mailbox."""

def _lookup(self, key=None): """Return (start, stop) or raise KeyError."""

--- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -469,9 +469,10 @@ class Listener(object): ''' Close the bound socket or named pipe of self. '''

address = property(lambda self: self._listener._address) last_accepted = property(lambda self: self._listener._last_accepted) @@ -609,9 +610,13 @@ class SocketListener(object): return Connection(s.detach()) def close(self):

def SocketClient(address):

--- a/Lib/multiprocessing/queues.py +++ b/Lib/multiprocessing/queues.py @@ -133,9 +133,13 @@ class Queue(object): def close(self): self._closed = True

def join_thread(self): debug('Queue.join_thread()')

--- a/Lib/poplib.py +++ b/Lib/poplib.py @@ -276,18 +276,23 @@ class POP3: def close(self): """Close the connection without assuming anything about it."""

#del = quit

--- a/Lib/selectors.py +++ b/Lib/selectors.py @@ -445,8 +445,10 @@ if hasattr(select, 'epoll'): return ready def close(self):

if hasattr(select, 'kqueue'): @@ -517,8 +519,10 @@ if hasattr(select, 'kqueue'): return ready def close(self):

Choose the best implementation: roughly, epoll|kqueue > poll > select.

--- a/Lib/shelve.py +++ b/Lib/shelve.py @@ -138,17 +138,21 @@ class Shelf(collections.MutableMapping): self.close() def close(self):

def del(self): if not hasattr(self, 'writeback'):

--- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -855,12 +855,16 @@ class SMTP: def close(self): """Close the connection to the SMTP server."""

def quit(self): """Terminate the SMTP session."""

--- a/Lib/sunau.py +++ b/Lib/sunau.py @@ -295,9 +295,11 @@ class Au_read: self._soundpos = pos def close(self):

class Au_write: @@ -438,9 +440,10 @@ class Au_write: self._patchheader() self._file.flush() finally:

# # private methods

--- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -449,26 +449,26 @@ class _Stream: if self.closed: return

-

-

def _init_read_gz(self): """Initialize for reading a gzip compressed fileobj. @@ -1705,18 +1705,19 @@ class TarFile(object): if self.closed: return

-

def getmember(self, name): """Return a TarInfo object for member name'. If name' can not be

--- a/Lib/telnetlib.py +++ b/Lib/telnetlib.py @@ -264,12 +264,13 @@ class Telnet: def close(self): """Close the connection."""

def get_socket(self): """Return the socket object used internally."""

--- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -357,9 +357,11 @@ class _TemporaryFileCloser: def close(self, unlink=_os.unlink): if not self.close_called and self.file is not None: self.close_called = True

# Need to ensure the file is deleted on del def del(self):

--- a/Lib/urllib/response.py +++ b/Lib/urllib/response.py @@ -43,11 +43,15 @@ class addclosehook(addbase): self.hookargs = hookargs def close(self):

class addinfo(addbase):

--- a/Lib/wave.py +++ b/Lib/wave.py @@ -186,10 +186,11 @@ class Wave_read: self._soundpos = 0 def close(self):

def tell(self): return self._soundpos @@ -428,17 +429,18 @@ class Wave_write: self._patchheader() def close(self):

# # Internal methods.

--- a/Lib/xml/sax/expatreader.py +++ b/Lib/xml/sax/expatreader.py @@ -211,17 +211,19 @@ class ExpatParser(xmlreader.IncrementalP self._err_handler.fatalError(exc) def close(self):

def _reset_cont_handler(self): self._parser.ProcessingInstructionHandler = [](#l25.31)

--- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -446,8 +446,13 @@ class ExpatParser: self._parser.Parse(data, 0) def close(self):

--------------------------------------------------------------------

XML-RPC marshalling and unmarshalling code

@@ -1079,8 +1084,10 @@ class GzipDecodedResponse(gzip.GzipFile gzip.GzipFile.init(self, mode="rb", fileobj=self.io) def close(self):

--------------------------------------------------------------------

@@ -1235,9 +1242,10 @@ class Transport: # Used in the event of socket errors. # def close(self):

## # Send HTTP request.

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -24,6 +24,10 @@ Core and Builtins Library ------- +- Issue #23865: close() methods in multiple modules now are idempotent and more