[Python-checkins] cpython (2.7): Fix added for recent changes in non-threading environments.

vinay.sajip python-checkins at python.org
Thu Feb 23 21:57:21 CET 2012


http://hg.python.org/cpython/rev/2ab3a97d544c
changeset:   75220:2ab3a97d544c
branch:      2.7
parent:      75210:b5cb819404aa
user:        Vinay Sajip <vinay_sajip at yahoo.co.uk>
date:        Thu Feb 23 20:45:03 2012 +0000
summary:
  Fix added for recent changes in non-threading environments.

files:
  Lib/logging/__init__.py |  10 ++++++++--
  Lib/logging/handlers.py |  25 ++++++++++++++++++++-----
  2 files changed, 28 insertions(+), 7 deletions(-)


diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -828,9 +828,12 @@
         """
         Flushes the stream.
         """
-        with self.lock:
+        self.acquire()
+        try:
             if self.stream and hasattr(self.stream, "flush"):
                 self.stream.flush()
+        finally:
+            self.release()
 
     def emit(self, record):
         """
@@ -901,13 +904,16 @@
         """
         Closes the stream.
         """
-        with self.lock:
+        self.acquire()
+        try:
             if self.stream:
                 self.flush()
                 if hasattr(self.stream, "close"):
                     self.stream.close()
                 StreamHandler.close(self)
                 self.stream = None
+        finally:
+            self.release()
 
     def _open(self):
         """
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -562,10 +562,13 @@
         """
         Closes the socket.
         """
-        with self.lock:
+        self.acquire()
+        try:
             if self.sock:
                 self.sock.close()
                 self.sock = None
+        finally:
+            self.release()
         logging.Handler.close(self)
 
 class DatagramHandler(SocketHandler):
@@ -767,9 +770,12 @@
         """
         Closes the socket.
         """
-        with self.lock:
+        self.acquire()
+        try:
             if self.unixsocket:
                 self.socket.close()
+        finally:
+            self.release()
         logging.Handler.close(self)
 
     def mapPriority(self, levelName):
@@ -1097,8 +1103,11 @@
 
         This version just zaps the buffer to empty.
         """
-        with self.lock:
+        self.acquire()
+        try:
             self.buffer = []
+        finally:
+            self.release()
 
     def close(self):
         """
@@ -1146,17 +1155,23 @@
         records to the target, if there is one. Override if you want
         different behaviour.
         """
-        with self.lock:
+        self.acquire()
+        try:
             if self.target:
                 for record in self.buffer:
                     self.target.handle(record)
                 self.buffer = []
+        finally:
+            self.release()
 
     def close(self):
         """
         Flush, set the target to None and lose the buffer.
         """
         self.flush()
-        with self.lock:
+        self.acquire()
+        try:
             self.target = None
             BufferingHandler.close(self)
+        finally:
+            self.release()

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list