Python 2.7.3 x64 wxPython 2.8 x64
Been reading quite a bit on python threading and multiprocessing, particularly some articles by Doug Hellmann, which have helped tremendously. However, I'm confused about one thing...
I thought the Python multiprocessing module was more-or-less a drop-in replacement for the threading module, excepting that args must be picklable, but I'm finding that in order not to block my GUI, I must first create a new thread with threading.Thread then multiprocess within that thread with multiprocessing.Process. This works, and works well, but it seems a bit kludgey to me.
If I try to directly multiprocess without first threading, then my GUI still blocks until the multiprocessing job is done. Is that working as designed, or am I missing something fundamental about the multiprocessing module?
If examples are needed, I can provide them.
Thanks,
-RMWChaos
An example was requested...
Assuming that onProcess() is triggered by a button in the GUI, this blocks the GUI...
import time
import multiprocessing as mp
def myWorker(a, b):
time.sleep(0.1)
print '{} * {} = {}'.format(a, b, a*b)
def onProcess(event):
jobs = mp.cpu_count() * 2
a = 5
b = 10
for job in range(jobs):
mp.Process(target = myWorker, args = (a, b,)).start()
While this doesn't...
import time
import multiprocessing as mp
import threading as th
def myWorker(a, b):
time.sleep(0.1)
print '{} * {} = {}'.format(a, b, a*b)
def onProcess(event):
a = 5
b = 10
th.Thread(target = myThread, args = [a, b,]).start()
def myThread(a, b):
jobs = mp.cpu_count() * 2
for job in range(jobs):
mp.Process(target = myWorker, args = (a, b,)).start()