Added multiprocessing

Added multiprocessing as number of processes equals to number of cpu cores.
This commit is contained in:
Lerking
2018-05-08 06:24:24 +02:00
committed by GitHub
parent f495978381
commit 827cae3b7d

View File

@@ -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()
@@ -70,7 +70,7 @@ folderlist = []
cnt = 0
srcdir = ''
destdir = ''
#num_cores = multiprocessing.cpu_count()
num_cores = multiprocessing.cpu_count()
fileindex = 0
filecnt = 0
incinc = ''
@@ -336,21 +336,22 @@ class ExampleApp:
print("Creating shared Queue")
queue = Queue()
print("Creating Worker")
worker = Worker(queue, self.filecnt, filelist)
for n in num_cores:
print("Creating Worker", n)
worker[n] = Worker(queue, self.filecnt, filelist)
print("Creating Listener")
listener = Listener(queue)
listener.connect("updated",self.callbackDisplay)
listener.connect("finished",self.callbackFinished)
print("Creating Listener", n)
listener[n] = Listener(queue)
listener[n].connect("updated",self.callbackDisplay)
listener[n].connect("finished",self.callbackFinished)
print("Starting Listener")
thread = threading.Thread(target=listener.go, args=())
thread.start()
print("Starting Listener", n)
thread[n] = threading.Thread(target=listener[n].go, args=())
thread[n].start()
print("Starting Worker")
self.process = Process(target=worker.go, args=())
self.process.start()
print("Starting Worker", n)
self.process = Process(target=worker[n].go, args=())
self.process.start()