From 827cae3b7da5f3ada1a1859423708d7022cd681c Mon Sep 17 00:00:00 2001 From: Lerking <33354709+Lerking@users.noreply.github.com> Date: Tue, 8 May 2018 06:24:24 +0200 Subject: [PATCH] Added multiprocessing Added multiprocessing as number of processes equals to number of cpu cores. --- Gui test/h2inc_gtk.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Gui test/h2inc_gtk.py b/Gui test/h2inc_gtk.py index acad1f7..f64427c 100755 --- a/Gui test/h2inc_gtk.py +++ b/Gui test/h2inc_gtk.py @@ -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()