Working on multiprocessing

This commit is contained in:
2018-05-09 21:05:29 +02:00
parent e0683c4670
commit 147bdc8a65
8 changed files with 246 additions and 66 deletions
+11 -10
View File
@@ -11,10 +11,9 @@ from threading import Thread
import threading
import globvar
import h2inc_fp
import time
num_cores = multiprocessing.cpu_count()
lock = threading.Lock()
queue = 0
def process_queue():
print("Worker {} working...".format(threading.current_thread().name))
@@ -26,19 +25,19 @@ def process_queue():
#self.queue.put((1.0, "finished"))
#print("The worker has finished.")
while True:
cfile = queue.get()
cfile = globvar.queue.get()
print(cfile)
h2inc_fp.process_file(cfile)
queue.task_done()
globvar.queue.task_done()
def start_workers():
global queue
print("Creating shared Queue")
queue = Queue()
ts = time.time()
globvar.queue = Queue()
print("Number of cores:", num_cores)
print("Number of cores:", globvar.num_cores)
for n in range(num_cores):
for n in range(globvar.num_cores):
print("Creating Worker", n)
worker = threading.Thread(target=process_queue)
@@ -47,8 +46,10 @@ def start_workers():
for cfile in globvar.filelist:
print("Queueing {}".format(cfile))
queue.put(cfile)
globvar.queue.put(cfile)
queue.join()
globvar.queue.join()
te = time.time()-ts
print("Processing time: ", te)
return