h2inc_gtk.py split

h2inc_gtk.py split into h2inc_globals.py (global variables), h2inc_mp.py (multiprocessing) and h2inc_fp.py (file processing)
This commit is contained in:
Lerking
2018-05-08 11:01:39 +02:00
committed by GitHub
parent 827cae3b7d
commit 30894e1b39
4 changed files with 181 additions and 176 deletions
+55
View File
@@ -0,0 +1,55 @@
# You are free to use and/or change this code for
# your own needs.
# Original code (c)2018 Jan Lerking
# Program to convert C-header (*.h) files to nasm include files (*.inc),
# for direct usage in assembly programming using nasm/yasm.
import multiprocessing
from queue import Queue
from threading import Thread
import threading
from h2inc_globals import filelist
from h2inc_fp import process_file
num_cores = multiprocessing.cpu_count()
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)")
#for i in range(self.filecnt):
#proportion = (float(i+1))/self.filecnt
#self.queue.put((proportion, "working...", i))
#time.sleep(0.01)
#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()
def start_workers():
print("Creating shared Queue")
queue = Queue()
print("Number of cores:", num_cores)
for n in range(num_cores):
print("Creating Worker", n)
worker = Worker(queue)
worker.deamon = True
worker.start()
for cfile in filelist:
print("Queueing {}".format(cfile))
queue.put(cfile)
queue.join()
return