I've a Driver class which has an instance method write. I'm trying to use Python multiprocessing to apply this instance method on objects in queue. Here's my code.
class Driver:
def __init__(self, arg1, arg2, arg3):
#initialize
def write(self, key):
# do something
Here's how I'm calling it on a collection.
def write_to_db(key, d=Driver(arg1=None, arg2=None, arg3=None)):
d.write(key)
def main():
.........
with multiprocessing.Pool(processes=8) as pool:
driver = Driver(arg1=arg1, arg2=arg2, arg3=arg3)
_ = pool.map(write_to_db, (arr, driver))
I get the following error:
TypeError: can't pickle _thread.RLock objects
How can I get this right?
if __name__ == "__main__"clause and if I see it right, yourmain()-function is outside of the classDriver,right?pool.map,write_to_dbwill only be run twice, once witharras the argument, and once withdriver. Is that really what you intended?