Merged fix added for recent changes in non-threading environments.

This commit is contained in:
Vinay Sajip 2012-02-23 20:51:18 +00:00
commit 323e4fb864
2 changed files with 28 additions and 7 deletions

View File

@ -914,9 +914,12 @@ class StreamHandler(Handler):
""" """
Flushes the stream. Flushes the stream.
""" """
with self.lock: self.acquire()
try:
if self.stream and hasattr(self.stream, "flush"): if self.stream and hasattr(self.stream, "flush"):
self.stream.flush() self.stream.flush()
finally:
self.release()
def emit(self, record): def emit(self, record):
""" """
@ -965,13 +968,16 @@ class FileHandler(StreamHandler):
""" """
Closes the stream. Closes the stream.
""" """
with self.lock: self.acquire()
try:
if self.stream: if self.stream:
self.flush() self.flush()
if hasattr(self.stream, "close"): if hasattr(self.stream, "close"):
self.stream.close() self.stream.close()
StreamHandler.close(self) StreamHandler.close(self)
self.stream = None self.stream = None
finally:
self.release()
def _open(self): def _open(self):
""" """

View File

@ -593,11 +593,14 @@ class SocketHandler(logging.Handler):
""" """
Closes the socket. Closes the socket.
""" """
with self.lock: self.acquire()
try:
if self.sock: if self.sock:
self.sock.close() self.sock.close()
self.sock = None self.sock = None
logging.Handler.close(self) logging.Handler.close(self)
finally:
self.release()
class DatagramHandler(SocketHandler): class DatagramHandler(SocketHandler):
""" """
@ -792,9 +795,12 @@ class SysLogHandler(logging.Handler):
""" """
Closes the socket. Closes the socket.
""" """
with self.lock: self.acquire()
try:
self.socket.close() self.socket.close()
logging.Handler.close(self) logging.Handler.close(self)
finally:
self.release()
def mapPriority(self, levelName): def mapPriority(self, levelName):
""" """
@ -1138,8 +1144,11 @@ class BufferingHandler(logging.Handler):
This version just zaps the buffer to empty. This version just zaps the buffer to empty.
""" """
with self.lock: self.acquire()
try:
self.buffer = [] self.buffer = []
finally:
self.release()
def close(self): def close(self):
""" """
@ -1189,20 +1198,26 @@ class MemoryHandler(BufferingHandler):
The record buffer is also cleared by this operation. The record buffer is also cleared by this operation.
""" """
with self.lock: self.acquire()
try:
if self.target: if self.target:
for record in self.buffer: for record in self.buffer:
self.target.handle(record) self.target.handle(record)
self.buffer = [] self.buffer = []
finally:
self.release()
def close(self): def close(self):
""" """
Flush, set the target to None and lose the buffer. Flush, set the target to None and lose the buffer.
""" """
self.flush() self.flush()
with self.lock: self.acquire()
try:
self.target = None self.target = None
BufferingHandler.close(self) BufferingHandler.close(self)
finally:
self.release()
class QueueHandler(logging.Handler): class QueueHandler(logging.Handler):