use 'with' lock syntax instead of acquire/release
This commit is contained in:
parent
0283bb0e91
commit
15f24eb26b
|
|
@ -56,7 +56,9 @@ def _print(marker, data, scroll=False):
|
||||||
hexs = strhex(data)
|
hexs = strhex(data)
|
||||||
s = '%s (% 8.3f) [%s %s %s %s] %s' % (marker, t, hexs[0:2], hexs[2:4], hexs[4:8], hexs[8:], repr(data))
|
s = '%s (% 8.3f) [%s %s %s %s] %s' % (marker, t, hexs[0:2], hexs[2:4], hexs[4:8], hexs[8:], repr(data))
|
||||||
|
|
||||||
print_lock.acquire()
|
with print_lock:
|
||||||
|
# allow only one thread at a time to write to the console, otherwise
|
||||||
|
# the output gets garbled, especially with ANSI codes.
|
||||||
|
|
||||||
if interactive and scroll:
|
if interactive and scroll:
|
||||||
# scroll the entire screen above the current line up by 1 line
|
# scroll the entire screen above the current line up by 1 line
|
||||||
|
|
@ -72,8 +74,6 @@ def _print(marker, data, scroll=False):
|
||||||
else:
|
else:
|
||||||
sys.stdout.write('\n')
|
sys.stdout.write('\n')
|
||||||
|
|
||||||
print_lock.release()
|
|
||||||
|
|
||||||
|
|
||||||
def _error(text, scroll=False):
|
def _error(text, scroll=False):
|
||||||
_print("!!", text, scroll)
|
_print("!!", text, scroll)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue