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