-
Notifications
You must be signed in to change notification settings - Fork 1
/
worker.py
37 lines (30 loc) · 1.25 KB
/
worker.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
from multiprocessing import cpu_count, Process
from server import TaskManager
import tester_dbisam
import config
def __worker_function(job_queue, result_queue):
while True:
password_start, password_end, letters, data = job_queue.get()
result, password = tester_dbisam.probe_start(password_start,
password_end,
letters,
data)
result_queue.put((result, password))
job_queue.task_done()
def __start_workers(m):
job_queue, result_queue = m.get_job_queue(), m.get_result_queue()
nr_of_processes = cpu_count()
processes = [Process(target=__worker_function,
args=(job_queue, result_queue))
for i in range(nr_of_processes)]
for p in processes:
p.start()
return nr_of_processes
if __name__ == "__main__":
TaskManager.register("get_job_queue")
TaskManager.register("get_result_queue")
m = TaskManager(address=(config.SERVER_IP, config.SERVER_PORT),
authkey=config.SERVER_PASSWORD)
m.connect()
nr_of_processes = __start_workers(m)
print(nr_of_processes, "workers started")