修改二维码打印逻辑

防止并发输出日志时错位

Signed-off-by: Gardel <sunxinao@hotmail.com>
This commit is contained in:
Gardel
2021-09-25 17:35:09 +08:00
parent 68a508e30a
commit f7c8ff4daa
2 changed files with 16 additions and 11 deletions

View File

@@ -65,13 +65,13 @@ def print_qrcode(path):
black_block = '\033[0;37;40m '
new_line = '\033[0m\n'
print('', flush=False)
output = '\n'
for i in range(module_count + 2):
print(white_block, end='', flush=False)
print('', end=new_line, flush=False)
output += white_block
output += new_line
i = y_flag
while i < height - y_flag:
print(white_block, end='', flush=False)
output += white_block
j = x_flag
while j < width - x_flag:
total = 0
@@ -82,12 +82,13 @@ def print_qrcode(path):
mid = (2 ** info['bitdepth']) / 2
black = avg < mid
if black:
print(black_block, end='', flush=False)
output += black_block
else:
print(white_block, end='', flush=False)
output += white_block
j += scale
print(white_block, end=new_line, flush=False)
output += white_block + new_line
i += scale
for i in range(module_count + 2):
print(white_block, end='', flush=False)
print('', end=new_line, flush=True)
output += white_block
output += new_line
print(output, end='', flush=True)

View File

@@ -177,10 +177,14 @@ class UserJob:
elif result_code == 2:
break
elif result_code == 3:
try:
os.remove(png_path)
except Exception as e:
UserLog.add_quick_log('无法删除文件: {}'.format(e)).flush()
image_uuid = self.download_code()
try:
os.remove(png_path)
except BaseException as e:
except Exception as e:
UserLog.add_quick_log('无法删除文件: {}'.format(e)).flush()
self.session.get(API_USER_LOGIN, allow_redirects=True)
@@ -213,7 +217,7 @@ class UserJob:
UserLog.add_log(UserLog.MESSAGE_QRCODE_DOWNLOADED.format(png_path)).flush()
return result.get('uuid'), png_path
raise KeyError('获取二维码失败: {}'.format(result.get('result_message')))
except BaseException as e:
except Exception as e:
UserLog.add_quick_log(
UserLog.MESSAGE_QRCODE_FAIL.format(e, self.retry_time)).flush()
time.sleep(self.retry_time)