I'm trying to use multiprocessing.Pool
in my code but I got this exception:
PicklingError: Can't pickle <type 'instancemethod'>: attribute lookup __builtin__.instancemethod failed
I found this and it's preferred solution recipe
my problem is that I don't know how to implement this solution in my code.
my code is something like that:
class G(class):
def submit(self,data):
cmd = self.createCommand(data)
subprocess.call(cmd, shell=True)
# call for a short command
def main(self):
self.pool = multiprocessing.Pool()
while(True):
data = self.GenerateData()
self.pool.apply_async(self.Submit, args=(data,))
some notes:
- the main
while
should work for a long time (few days) - I'm using
pool
for performance purposes, if you have a better solution I will be glad to here it
update:
after using @unutbu solution I got the next exception:
PicklingError: Can't pickle <type 'thread.lock'>: attribute lookup thread.lock failed
now , all the solutions I found were talking about Queue.Queue
and mp.Pool.map
but I'm not using those attributes so I can't figure it out.
This is an application of Steven Bethard's solution to your situation: