summaryrefslogtreecommitdiffstats
path: root/Lib/logging/__init__.py
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2012-02-23 19:45:52 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2012-02-23 19:45:52 (GMT)
commit0abf61db4dd0d008ad06c84cd882fb84e5c11181 (patch)
tree79618089e71f10d580f9eaf40a2da684857c6356 /Lib/logging/__init__.py
parentba528f57caea59841be8785ee7b0bc28293d47b1 (diff)
downloadcpython-0abf61db4dd0d008ad06c84cd882fb84e5c11181.zip
cpython-0abf61db4dd0d008ad06c84cd882fb84e5c11181.tar.gz
cpython-0abf61db4dd0d008ad06c84cd882fb84e5c11181.tar.bz2
logging: Added locking in flush() and close() handler methods. Thanks to Fayaz Yusuf Khan for the suggestion.
Diffstat (limited to 'Lib/logging/__init__.py')
-rw-r--r--Lib/logging/__init__.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 3faad4f..b4c823d 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1,4 +1,4 @@
-# Copyright 2001-2010 by Vinay Sajip. All Rights Reserved.
+# Copyright 2001-2012 by Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
@@ -16,9 +16,9 @@
"""
Logging package for Python. Based on PEP 282 and comments thereto in
-comp.lang.python, and influenced by Apache's log4j system.
+comp.lang.python.
-Copyright (C) 2001-2011 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
"""
@@ -917,8 +917,9 @@ class StreamHandler(Handler):
"""
Flushes the stream.
"""
- if self.stream and hasattr(self.stream, "flush"):
- self.stream.flush()
+ with self.lock:
+ if self.stream and hasattr(self.stream, "flush"):
+ self.stream.flush()
def emit(self, record):
"""
@@ -969,12 +970,13 @@ class FileHandler(StreamHandler):
"""
Closes the stream.
"""
- if self.stream:
- self.flush()
- if hasattr(self.stream, "close"):
- self.stream.close()
- StreamHandler.close(self)
- self.stream = None
+ with self.lock:
+ if self.stream:
+ self.flush()
+ if hasattr(self.stream, "close"):
+ self.stream.close()
+ StreamHandler.close(self)
+ self.stream = None
def _open(self):
"""