forked from Damianonymous/ChaturbateRecorder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessing_worker.py
More file actions
executable file
·54 lines (46 loc) · 1.68 KB
/
Copy pathprocessing_worker.py
File metadata and controls
executable file
·54 lines (46 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import subprocess
import time
import threading
import os
import json
from tqdm import tqdm
from mmisp import process
class ProcessingWorker(threading.Thread):
def __init__(self, queue, cmd):
super().__init__()
self.daemon = True
self.cmd = cmd
self.queue = queue
self.sleep = 1 # 60
self.current_file = None
self.pbar = None
def setPbar(self, pbar: tqdm):
self.pbar = pbar
def update_progress(self, percent_complete):
if isinstance(self.pbar, tqdm):
self.pbar.n = percent_complete
self.pbar.refresh()
def run(self):
while True:
while self.queue.empty():
time.sleep(self.sleep)
parameters = self.queue.get()
self.current_file = parameters['path']
if self.cmd == 'mmisp':
with open('process.json', 'r') as f:
process.run(parameters['path'],
json.load(f),
progress_callback=self.update_progress)
else:
replacements = {
'path': parameters['path'],
'filename': os.path.split(parameters['path'])[-1],
'directory': os.path.dirname(parameters['path']),
'file': os.path.splitext(os.path.split(parameters['path'])[-1])[0],
'model': parameters['model']
}
cmd = self.cmd.format(replacements)
subprocess.call(cmd.split())
self.pbar.clear()
self.pbar.display('Waiting')
self.current_file = None