Hello all,
I am trying to get some basic code that uses the multiprocessing module to work in a Pro 3.1 toolbox but it just won't play nice. The code:
import time
import arcpy
import multiprocessing as mp
def work_log(work_data):
arcpy.AddMessage(" Process %s waiting %s seconds" % (work_data[0], work_data[1]))
time.sleep(int(work_data[1]))
arcpy.AddMessage(" Process %s Finished." % work_data[0])
def pool_handler(work):
p = mp.Pool(2)
p.map(work_log, work)
if __name__ == '__main__':
work = (["A", 5], ["B", 2], ["C", 1], ["D", 3])
pool_handler(work)
If I run this in an .atnx or .pyt I get the same error:
PicklingError: Can't pickle <function work_log at 0x00000134B287D430>: attribute lookup work_log on __main__ failed
I also get 2 new instances of Pro open automatically if I run in a .pyt toolbox, I assume due to lack of __main__.
Does anyone have any advice on how to get something like this running in a Pro toolbox (preferably .pyt)?
I came across a similar question here https://community.esri.com/t5/python-questions/using-multiprocessing/m-p/1280108 but it has never been answered.
Thanks!