nondanee / weiboPicDownloader

Download weibo images without logging-in
GNU General Public License v3.0
266 stars 63 forks source link

Ctrl+C的优雅终止? #21

Closed nondanee closed 5 years ago

nondanee commented 6 years ago

如何在KeyboardInterrupt时终止所有下载线程 并将下载到一半的不完整文件删除(因下次下载检测到文件存在将直接跳过)

futue.cancel()无法结束running状态的线程

Python: concurrent.futures How to make it cancelable? https://stackoverflow.com/questions/42782953/python-concurrent-futures-how-to-make-it-cancelable Is there a way to stop a running process in concurrent.futures? https://stackoverflow.com/questions/16050212/is-there-a-way-to-stop-a-running-process-in-concurrent-futures How do you kill Futures once they have started? https://stackoverflow.com/questions/29177490/how-do-you-kill-futures-once-they-have-started

解决方案1: 线程内检查全局变量 解决方案2: 关闭线程池并手动杀死子线程

有没有更加优雅的方式呢?

nondanee commented 5 years ago

现阶段用 futue.cancel() 取消未执行的任务,等待所有 running 的线程结束在关闭