thread safe logging+stdout (no more overlapping of log messages and raw output)

This commit is contained in:
Miroslav Stampar 2011-06-22 14:53:42 +00:00
parent 84bc8c3a37
commit 4ca37901da

View File

@ -663,6 +663,7 @@ def dataToStdout(data, forceOutput=False):
if not ('threadException' in kb and kb.threadException): if not ('threadException' in kb and kb.threadException):
if forceOutput or not getCurrentThreadData().disableStdOut: if forceOutput or not getCurrentThreadData().disableStdOut:
try: try:
logging._acquireLock()
# Reference: http://bugs.python.org/issue1602 # Reference: http://bugs.python.org/issue1602
if IS_WIN: if IS_WIN:
output = data.encode('ascii', "replace") output = data.encode('ascii', "replace")
@ -684,6 +685,7 @@ def dataToStdout(data, forceOutput=False):
sys.stdout.write(data.encode(UNICODE_ENCODING)) sys.stdout.write(data.encode(UNICODE_ENCODING))
finally: finally:
sys.stdout.flush() sys.stdout.flush()
logging._releaseLock()
def dataToSessionFile(data): def dataToSessionFile(data):
if not conf.sessionFile or kb.suppressSession: if not conf.sessionFile or kb.suppressSession:
@ -772,7 +774,9 @@ def readInput(message, default=None):
data = default data = default
else: else:
logging._acquireLock()
data = raw_input(message.encode(sys.stdout.encoding or UNICODE_ENCODING)) data = raw_input(message.encode(sys.stdout.encoding or UNICODE_ENCODING))
logging._releaseLock()
if not data: if not data:
data = default data = default