Skip to content

Commit

Permalink
修复:输入 jobs -f 进入连续显示 任务状态 后,无法退出 #17
Browse files Browse the repository at this point in the history
  • Loading branch information
Aruelius committed May 27, 2020
1 parent 81bdef0 commit 3dae3b0
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions cloud189/cli/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,26 @@ def _size_to_msg(now_size, total_size, count, pid, task) -> (str, bool):

@staticmethod
def _show_task(pid, task, follow=False):
TaskManager.running = True # 相当于每次执行 jobs -f 都初始化
def stop_show_task():
"""
停止显示任务状态
问题:由于线程执行的是阻塞操作,不知道自己被结束了,
它还在等待一个 input,所以在任务状态 Finnish 之后需要回车。
"""
while TaskManager.running:
stop_signal = input()
if stop_signal:
TaskManager.running = False
time.sleep(1)
if follow: threading.Thread(target=stop_show_task).start()
global output_list
now_size, total_size, count = task.get_process()
# TODO: 出现 now_size > total_size, 断点续传出了问题
msg, quick_up = TaskManager._size_to_msg(now_size, total_size, count, pid, task)
while now_size < total_size:
if not TaskManager.running:
break
msg, quick_up = TaskManager._size_to_msg(now_size, total_size, count, pid, task)
if follow:
output_list[pid] = msg
Expand All @@ -88,12 +103,13 @@ def _show_task(pid, task, follow=False):
break
if now_size == total_size:
msg, _ = TaskManager._size_to_msg(now_size, total_size, count, pid,task)
if follow:
if follow and TaskManager.running:
output_list[pid] = msg
if follow:
if follow and TaskManager.running:
output_list.append(f"[{pid}] finished")
else:
print(msg)
TaskManager.running = False
elif not TaskManager.running: pass
else: print(msg)

def _show_task_bar(self, pid=None, follow=False):
"""多行更新状态栏"""
Expand Down

0 comments on commit 3dae3b0

Please sign in to comment.