mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-07 12:05:35 +00:00
Fix interrupt immediately
This commit is contained in:
parent
020ade73cd
commit
81198cad89
@ -47,6 +47,7 @@ PROXY_START_MAX = config_manager.get_float('REQUESTS', 'proxy_start_max')
|
|||||||
DEFAULT_VIDEO_WORKERS = config_manager.get_int('M3U8_DOWNLOAD', 'default_video_workser')
|
DEFAULT_VIDEO_WORKERS = config_manager.get_int('M3U8_DOWNLOAD', 'default_video_workser')
|
||||||
DEFAULT_AUDIO_WORKERS = config_manager.get_int('M3U8_DOWNLOAD', 'default_audio_workser')
|
DEFAULT_AUDIO_WORKERS = config_manager.get_int('M3U8_DOWNLOAD', 'default_audio_workser')
|
||||||
MAX_TIMEOOUT = config_manager.get_int("REQUESTS", "timeout")
|
MAX_TIMEOOUT = config_manager.get_int("REQUESTS", "timeout")
|
||||||
|
MAX_INTERRUPT_COUNT = 3
|
||||||
SEGMENT_MAX_TIMEOUT = config_manager.get_int("M3U8_DOWNLOAD", "segment_timeout")
|
SEGMENT_MAX_TIMEOUT = config_manager.get_int("M3U8_DOWNLOAD", "segment_timeout")
|
||||||
|
|
||||||
|
|
||||||
@ -83,6 +84,9 @@ class M3U8_Segments:
|
|||||||
# Stopping
|
# Stopping
|
||||||
self.interrupt_flag = threading.Event()
|
self.interrupt_flag = threading.Event()
|
||||||
self.download_interrupted = False
|
self.download_interrupted = False
|
||||||
|
self.interrupt_count = 0
|
||||||
|
self.force_stop = False
|
||||||
|
self.interrupt_lock = threading.Lock()
|
||||||
|
|
||||||
# OTHER INFO
|
# OTHER INFO
|
||||||
self.info_maxRetry = 0
|
self.info_maxRetry = 0
|
||||||
@ -157,11 +161,23 @@ class M3U8_Segments:
|
|||||||
Set up a signal handler for graceful interruption.
|
Set up a signal handler for graceful interruption.
|
||||||
"""
|
"""
|
||||||
def interrupt_handler(signum, frame):
|
def interrupt_handler(signum, frame):
|
||||||
|
with self.interrupt_lock:
|
||||||
|
self.interrupt_count += 1
|
||||||
|
if self.interrupt_count >= MAX_INTERRUPT_COUNT:
|
||||||
|
self.force_stop = True
|
||||||
|
|
||||||
|
if self.force_stop:
|
||||||
|
console.print("\n[red]Force stop triggered! Exiting immediately.")
|
||||||
|
|
||||||
|
else:
|
||||||
if not self.interrupt_flag.is_set():
|
if not self.interrupt_flag.is_set():
|
||||||
console.print("\n[red]- Stopping download gracefully...")
|
remaining = MAX_INTERRUPT_COUNT - self.interrupt_count
|
||||||
#self.interrupt_flag.set() IN MODO DA NON TERMINARE SUBITO
|
console.print(f"\n[red]- Stopping gracefully... (Ctrl+C {remaining}x to force)")
|
||||||
self.download_interrupted = True
|
self.download_interrupted = True
|
||||||
#self.stop_event.set() IN MODO DA NON TERMINARE SUBITO
|
|
||||||
|
if remaining == 1:
|
||||||
|
self.interrupt_flag.set()
|
||||||
|
|
||||||
|
|
||||||
if threading.current_thread() is threading.main_thread():
|
if threading.current_thread() is threading.main_thread():
|
||||||
signal.signal(signal.SIGINT, interrupt_handler)
|
signal.signal(signal.SIGINT, interrupt_handler)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user