From 3a3a800798976b683a34b55bb7c8516d65365392 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sun, 9 Dec 2012 18:12:41 +0100 Subject: [PATCH] Make output thread-safe. --- dosagelib/output.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dosagelib/output.py b/dosagelib/output.py index a7952ab64..7576dc01e 100644 --- a/dosagelib/output.py +++ b/dosagelib/output.py @@ -4,6 +4,9 @@ from __future__ import print_function import time import sys +import threading + +lock = threading.Lock() class Output(object): """Print output with context, indentation and optional timestamps.""" @@ -34,8 +37,9 @@ class Output(object): timestamp = time.strftime('%H:%M:%S ') else: timestamp = '' - print('%s%s> %s' % (timestamp, self.context, s), file=file) - file.flush() + with lock: + print('%s%s> %s' % (timestamp, self.context, s), file=file) + file.flush() def writelines(self, lines, level=0): """Write multiple messages."""