From 678a8f9bc817c32b46e551a22ee886ebed2f42a8 Mon Sep 17 00:00:00 2001 From: lededev Date: Mon, 11 Oct 2021 10:24:46 +0800 Subject: [PATCH] Add signal handler --- AV_Data_Capture.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/AV_Data_Capture.py b/AV_Data_Capture.py index 8e1cb76..02ac84b 100755 --- a/AV_Data_Capture.py +++ b/AV_Data_Capture.py @@ -6,6 +6,7 @@ import sys import shutil import typing import urllib3 +import signal import config from datetime import datetime, timedelta @@ -223,6 +224,15 @@ def close_logfile(logdir: str): # 100MB的日志文件能缩小到3.7MB。 +def signal_handler(*args): + print('[!]Ctrl+C detected, Exit.') + sys.exit(9) + +def sigdebug_handler(*args): + config.G_conf_override["debug_mode:switch"] = not config.G_conf_override["debug_mode:switch"] + print('[!]Debug {}'.format('On' if config.getInstance().debug() else 'oFF')) + + # 新增失败文件列表跳过处理,及.nfo修改天数跳过处理,提示跳过视频总数,调试模式(-g)下详细被跳过文件,跳过小广告 def movie_lists(source_folder, regexstr): conf = config.getInstance() @@ -420,6 +430,11 @@ if __name__ == '__main__': print(f"[-]Main mode must be 1 or 2 or 3! You can run '{os.path.basename(sys.argv[0])} --help' for more help.") sys.exit(4) + signal.signal(signal.SIGINT, signal_handler) + if sys.platform == 'win32': + signal.signal(signal.SIGBREAK, sigdebug_handler) + else: + signal.signal(signal.SIGWINCH, sigdebug_handler) dupe_stdout_to_logfile(logdir) print('[*]================== AV Data Capture ===================')