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