I'm using ArcPy with multiprocessing to run area solar radiation tool. I keep getting this "Runtime Error The Product License has not been initialized". The script is still running and I can get results. But I wonder if this slows down the process and how I can avoid this error. Here is how I set up the multiprocessing part
# create a process pool
pool = Pool(processes=cpu_count())
pool.starmap(calcSolar,input_path)
pool.close()
pool.join()
I tried to change the number of processes and sometimes I didn't get this error. I'm very new to multiprocessing. Any help is appreciated!
see the code examples
Area Solar Radiation (Spatial Analyst)—ArcGIS Pro | Documentation
have you instantiated the spatial analyst extension by importing SA
from arcpy.sa import *
Yes. I imported arcpy.sa. I can get results though I got this error so I guess this configuration is okay but not optimal
Are you using a single use license, pulling from a concurrent use license manager or via ArcGIS Online?
I'm using the python environment from Pro and it uses a concurrent use license. Do I need a single use license?
Double check the LM when you run this script. You may be borrowing a license per multiprocess thread and hitting a cap.
I would check out and check in the spatial analyst extension in the worker function you are calling through multiprocessing.
I have the exactly the same Error. My script only uses arcpy in one step before the multiprocessing but not in the function used in the multiprocessing which is handled completely with gdal. This error occurs most of the times bu not always and apparently is related when the function modifies a numpy array or when the array is written in the band. I cannot understand what triggers the error because no arcpy method is called during the process.
def calculateStats(*args):
# This function doesn't use arcpy
f = functools.partial(calculateStats, in_data=in_data, z_data=z_data, out=out)
with multiprocessing.Pool(processes=2) as pool:
res = pool.map(f, coordinates)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
........
from ._arcgisscripting import *
RuntimeError: The Product License has not been initialized.
I'm working in a conda env I created with its arcpy installation. However, apparently arcpy points to a different installation.
sys.executable
Out[17]: '\\Anaconda3\\envs\\py37\\python.exe'
multiprocessing.__file__
Out[13]: '\\Anaconda3\\envs\\py37\\lib\\multiprocessing\\__init__.py'
arcpy.__file__
Out[14]: '\\AppData\\Local\\Programs\\ArcGIS\\Pro\\Resources\\ArcPy\\arcpy\\__init__.py'
Thanks
arcpy uses your Pro environment unless your clone includes it, it won't be available