Starting from where a following thread concluded Can't pickle type instancemethod that discussed a similar issue.
Here is an example code (taken from that post(simplified) that does solve a problem of using multipocessing from inside of class:
from multiprocessing import Pool, cpu_count
from multiprocessing.pool import ApplyResult
class Myclass(object):
def __init__(self):
pool = Pool(processes=3)
async_results = [ pool.apply_async(self, (i,)) for i in range(8) ]
pool.close()
map(ApplyResult.wait, async_results)
def __call__(self, i):
self.process_obj(i)
def __del__(self):
print "... Destructor"
def process_obj(self, i):
print "obj %d" % i
return "result"
Myclass()
Next trying a same code except this time Myclass() is inheriting from QtGui.QMainWindow:
from PyQt4 import QtCore, QtGui
from multiprocessing import Pool, cpu_count
from multiprocessing.pool import ApplyResult
app = QtGui.QApplication(sys.argv)
class Myclass(QtGui.QMainWindow):
def __init__(self):
super(Myclass, self).__init__()
pool = Pool(processes=3)
async_results = [ pool.apply_async(self, (i,)) for i in range(8) ]
pool.close()
map(ApplyResult.wait, async_results)
def __call__(self, i):
self.process_obj(i)
def __del__(self):
print "... Destructor"
def process_obj(self, i):
print "obj %d" % i
return "result"
Myclass()
Running it results to RuntimeError:
RuntimeError: super-class __init__() of type Myclass was never called