Added multiprocessing
Added multiprocessing as number of processes equals to number of cpu cores.
This commit is contained in:
+15
-14
@@ -14,7 +14,7 @@ import gi
|
|||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import Gtk, Gio, GObject as gobject
|
from gi.repository import Gtk, Gio, GObject as gobject
|
||||||
import time
|
import time
|
||||||
from multiprocessing import Process, Value, Lock, Pool, Queue
|
from multiprocessing import Process, Value, Lock, Pool, Queue, cpu_count
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
gobject.threads_init()
|
gobject.threads_init()
|
||||||
@@ -70,7 +70,7 @@ folderlist = []
|
|||||||
cnt = 0
|
cnt = 0
|
||||||
srcdir = ''
|
srcdir = ''
|
||||||
destdir = ''
|
destdir = ''
|
||||||
#num_cores = multiprocessing.cpu_count()
|
num_cores = multiprocessing.cpu_count()
|
||||||
fileindex = 0
|
fileindex = 0
|
||||||
filecnt = 0
|
filecnt = 0
|
||||||
incinc = ''
|
incinc = ''
|
||||||
@@ -336,21 +336,22 @@ class ExampleApp:
|
|||||||
print("Creating shared Queue")
|
print("Creating shared Queue")
|
||||||
queue = Queue()
|
queue = Queue()
|
||||||
|
|
||||||
print("Creating Worker")
|
for n in num_cores:
|
||||||
worker = Worker(queue, self.filecnt, filelist)
|
print("Creating Worker", n)
|
||||||
|
worker[n] = Worker(queue, self.filecnt, filelist)
|
||||||
|
|
||||||
print("Creating Listener")
|
print("Creating Listener", n)
|
||||||
listener = Listener(queue)
|
listener[n] = Listener(queue)
|
||||||
listener.connect("updated",self.callbackDisplay)
|
listener[n].connect("updated",self.callbackDisplay)
|
||||||
listener.connect("finished",self.callbackFinished)
|
listener[n].connect("finished",self.callbackFinished)
|
||||||
|
|
||||||
print("Starting Listener")
|
print("Starting Listener", n)
|
||||||
thread = threading.Thread(target=listener.go, args=())
|
thread[n] = threading.Thread(target=listener[n].go, args=())
|
||||||
thread.start()
|
thread[n].start()
|
||||||
|
|
||||||
print("Starting Worker")
|
print("Starting Worker", n)
|
||||||
self.process = Process(target=worker.go, args=())
|
self.process = Process(target=worker[n].go, args=())
|
||||||
self.process.start()
|
self.process.start()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user