Make output thread-safe.
This commit is contained in:
parent
75de0bc662
commit
3a3a800798
1 changed files with 6 additions and 2 deletions
|
@ -4,6 +4,9 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
|
|
||||||
|
lock = threading.Lock()
|
||||||
|
|
||||||
class Output(object):
|
class Output(object):
|
||||||
"""Print output with context, indentation and optional timestamps."""
|
"""Print output with context, indentation and optional timestamps."""
|
||||||
|
@ -34,6 +37,7 @@ class Output(object):
|
||||||
timestamp = time.strftime('%H:%M:%S ')
|
timestamp = time.strftime('%H:%M:%S ')
|
||||||
else:
|
else:
|
||||||
timestamp = ''
|
timestamp = ''
|
||||||
|
with lock:
|
||||||
print('%s%s> %s' % (timestamp, self.context, s), file=file)
|
print('%s%s> %s' % (timestamp, self.context, s), file=file)
|
||||||
file.flush()
|
file.flush()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue