fix bar eraser not letting program exit
This commit is contained in:
parent
71fc3001df
commit
e7b0fd9fff
|
@ -1,14 +1,10 @@
|
|||
import math
|
||||
import multiprocessing
|
||||
import os
|
||||
import random
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
from multiprocessing import Manager
|
||||
from pathlib import Path
|
||||
from threading import Thread
|
||||
|
||||
import numpy as np
|
||||
import yt_dlp as ydl_ydl
|
||||
|
@ -216,51 +212,63 @@ def download_video(args) -> dict:
|
|||
|
||||
|
||||
def bar_eraser(video_bars, eraser_exit):
|
||||
manager = Manager()
|
||||
queue = manager.dict()
|
||||
queue_lock = manager.Lock()
|
||||
while not eraser_exit.value:
|
||||
for i, item in enumerate(video_bars):
|
||||
if eraser_exit.value:
|
||||
return
|
||||
i = int(i)
|
||||
bar_lock = video_bars[i][1]
|
||||
if video_bars[i][1].acquire(timeout=0.1):
|
||||
bar = tqdm(position=video_bars[i][0], leave=False, bar_format='\x1b[2K')
|
||||
bar.close()
|
||||
bar_lock.release()
|
||||
|
||||
def eraser():
|
||||
nonlocal queue
|
||||
try:
|
||||
while not eraser_exit.value:
|
||||
for i in queue.keys():
|
||||
if eraser_exit.value:
|
||||
return
|
||||
i = int(i)
|
||||
lock = video_bars[i][1].acquire(timeout=0.1)
|
||||
bar_lock = video_bars[i][1]
|
||||
if lock:
|
||||
bar = tqdm(position=video_bars[i][0], leave=False, bar_format='\x1b[2K')
|
||||
bar.close()
|
||||
with queue_lock:
|
||||
del queue_dict[i]
|
||||
queue = queue_dict
|
||||
bar_lock.release()
|
||||
except KeyboardInterrupt:
|
||||
sys.exit(0)
|
||||
except multiprocessing.managers.RemoteError:
|
||||
sys.exit(0)
|
||||
except SystemExit:
|
||||
sys.exit(0)
|
||||
|
||||
try:
|
||||
Thread(target=eraser).start()
|
||||
while not eraser_exit.value:
|
||||
for i, item in enumerate(video_bars):
|
||||
if eraser_exit.value:
|
||||
return
|
||||
if is_manager_lock_locked(item[1]):
|
||||
with queue_lock:
|
||||
queue_dict = queue
|
||||
queue_dict[i] = True
|
||||
queue = queue_dict
|
||||
except KeyboardInterrupt:
|
||||
sys.exit(0)
|
||||
except multiprocessing.managers.RemoteError:
|
||||
sys.exit(0)
|
||||
except SystemExit:
|
||||
sys.exit(0)
|
||||
# Old queue and queue processor threads
|
||||
# manager = Manager()
|
||||
# queue = manager.dict()
|
||||
# queue_lock = manager.Lock()
|
||||
# def eraser():
|
||||
# nonlocal queue
|
||||
# try:
|
||||
# while not eraser_exit.value:
|
||||
# for i in queue.keys():
|
||||
# if eraser_exit.value:
|
||||
# return
|
||||
# i = int(i)
|
||||
# lock = video_bars[i][1].acquire(timeout=0.1)
|
||||
# bar_lock = video_bars[i][1]
|
||||
# if lock:
|
||||
# bar = tqdm(position=video_bars[i][0], leave=False, bar_format='\x1b[2K')
|
||||
# bar.close()
|
||||
# with queue_lock:
|
||||
# del queue_dict[i]
|
||||
# queue = queue_dict
|
||||
# bar_lock.release()
|
||||
# except KeyboardInterrupt:
|
||||
# sys.exit(0)
|
||||
# except multiprocessing.managers.RemoteError:
|
||||
# sys.exit(0)
|
||||
# except SystemExit:
|
||||
# sys.exit(0)
|
||||
#
|
||||
# try:
|
||||
# Thread(target=eraser).start()
|
||||
# while not eraser_exit.value:
|
||||
# for i, item in enumerate(video_bars):
|
||||
# if eraser_exit.value:
|
||||
# return
|
||||
# # Add bars to the queue
|
||||
# if is_manager_lock_locked(item[1]):
|
||||
# with queue_lock:
|
||||
# queue_dict = queue
|
||||
# queue_dict[i] = True
|
||||
# queue = queue_dict
|
||||
# except KeyboardInterrupt:
|
||||
# sys.exit(0)
|
||||
# except multiprocessing.managers.RemoteError:
|
||||
# sys.exit(0)
|
||||
# except SystemExit:
|
||||
# sys.exit(0)
|
||||
|
||||
|
||||
class ServiceExit(Exception):
|
||||
|
|
Reference in New Issue