-
Notifications
You must be signed in to change notification settings - Fork 11
/
Process.py
40 lines (33 loc) · 1.24 KB
/
Process.py
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
import threading
class ProcessParallel(object):
#Thanks https://stackoverflow.com/questions/11968689/python-multithreading-wait-till-all-threads-finished
def __init__(self, *jobs):
self.jobs = jobs
self.processes = []
self.processes_url = []
self.processes_extra = []
def append_process(self, *job, url=None, extra=None):
self.jobs = self.jobs + job
if (url != None and extra != None):
self.processes_url.append(url)
self.processes_extra.append(extra)
def fork_processes(self):
count = -1
for job in self.jobs:
try:
if (count == -1):
proc = threading.Thread(target=job)
self.processes.append(proc)
count+=1
else:
proc = threading.Thread(target=job, args=(self.processes_url[count], self.processes_extra[count]))
self.processes.append(proc)
count+=1
except Exception:
pass
def start_all(self):
for proc in self.processes:
proc.start()
def join_all(self):
for proc in self.processes:
proc.join()