new test for mp
This commit is contained in:
Binary file not shown.
@@ -14,7 +14,7 @@ import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk, Gio, GObject as gobject
|
||||
import time
|
||||
from multiprocessing import Process, Value, Lock, Pool, Queue
|
||||
from multiprocessing import Process, Value, Lock, Pool, Queue, cpu_count
|
||||
import threading
|
||||
|
||||
gobject.threads_init()
|
||||
@@ -38,6 +38,7 @@ class Listener(gobject.GObject):
|
||||
while True:
|
||||
# Listen for results on the queue and process them accordingly
|
||||
data = self.queue.get()
|
||||
print(data)
|
||||
# Check if finished
|
||||
if data[1]=="finished":
|
||||
print("Listener is finishing.")
|
||||
@@ -58,7 +59,7 @@ class Worker():
|
||||
for i in range(self.filecnt):
|
||||
proportion = (float(i+1))/self.filecnt
|
||||
self.queue.put((proportion, "working...", i))
|
||||
time.sleep(0.01)
|
||||
#time.sleep(0.01)
|
||||
process_file(filelist[i])
|
||||
self.queue.put((1.0, "finished"))
|
||||
print("The worker has finished.")
|
||||
@@ -70,7 +71,7 @@ folderlist = []
|
||||
cnt = 0
|
||||
srcdir = ''
|
||||
destdir = ''
|
||||
#num_cores = multiprocessing.cpu_count()
|
||||
num_cores = cpu_count()
|
||||
fileindex = 0
|
||||
filecnt = 0
|
||||
incinc = ''
|
||||
@@ -334,10 +335,11 @@ class ExampleApp:
|
||||
return
|
||||
|
||||
print("Creating shared Queue")
|
||||
queue = Queue()
|
||||
queue = Queue(num_cores)
|
||||
|
||||
print("Creating Worker")
|
||||
worker = Worker(queue, self.filecnt, filelist)
|
||||
for c in range(num_cores):
|
||||
print("Creating Worker: ", c)
|
||||
worker = Worker(queue, self.filecnt, filelist)
|
||||
|
||||
print("Creating Listener")
|
||||
listener = Listener(queue)
|
||||
|
Reference in New Issue
Block a user