use 'with' lock syntax instead of acquire/release

This commit is contained in:
Daniel Pavel 2013-05-06 15:35:20 +02:00
parent 0283bb0e91
commit 15f24eb26b
1 changed files with 16 additions and 16 deletions

View File

@ -56,7 +56,9 @@ def _print(marker, data, scroll=False):
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))
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:
# scroll the entire screen above the current line up by 1 line
@ -72,8 +74,6 @@ def _print(marker, data, scroll=False):
else:
sys.stdout.write('\n')
print_lock.release()
def _error(text, scroll=False):
_print("!!", text, scroll)