Major updates regarding global variables

This commit is contained in:
2018-05-08 22:03:11 +02:00
parent 4351221d7e
commit f88f5dcd0e
11 changed files with 116 additions and 104 deletions
+14 -15
View File
@@ -9,18 +9,15 @@ import multiprocessing
from queue import Queue
from threading import Thread
import threading
from h2inc_globals import filelist, cnt
from h2inc_fp import process_file
import globvar
import h2inc_fp
num_cores = multiprocessing.cpu_count()
lock = threading.Lock()
queue = 0
class Worker(Thread):
def __init__(self, queue):
Thread.__init__(self)
self.queue = queue
def go(self):
print("The worker has started doing some work (counting from 0 to 9)")
def process_queue():
print("Worker {} working...".format(threading.current_thread().name))
#for i in range(self.filecnt):
#proportion = (float(i+1))/self.filecnt
#self.queue.put((proportion, "working...", i))
@@ -28,12 +25,14 @@ class Worker(Thread):
#process_file(filelist[i])
#self.queue.put((1.0, "finished"))
#print("The worker has finished.")
while True:
cfile = self.queue.get()
process_file(cfile)
self.queue.task_done()
while True:
cfile = queue.get()
print(cfile)
h2inc_fp.process_file(cfile)
queue.task_done()
def start_workers():
global queue
print("Creating shared Queue")
queue = Queue()
@@ -42,11 +41,11 @@ def start_workers():
for n in range(num_cores):
print("Creating Worker", n)
worker = Worker(queue)
worker = threading.Thread(target=process_queue)
worker.deamon = True
worker.start()
for cfile in filelist:
for cfile in globvar.filelist:
print("Queueing {}".format(cfile))
queue.put(cfile)