I recently switched from ArcMap to ArcGIS Pro and am having trouble getting multiprocessing to work in an old script. It worked at one point in ArcMap, but recent testing shows it no longer works with a Python 2.7 interpreter either, so it needs to be overhauled in a way I can't figure out. Literally the only reason I need to run this in a separate process is because calling a script tool (TableToExcel) in a standalone script while debugging means none of the breakpoints will be hit after I run that line in my IDE (Debugging with ArcPy breakpoints after Point to Line). Any insight on how to get this working a separate process would be appreciated...
<SPAN class="keyword token">import</SPAN> os<SPAN class="punctuation token">,</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> multiprocessing
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">tbl2excl</SPAN><SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">,</SPAN> path<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>TableToExcel_conversion<SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">,</SPAN> path<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'ALIAS'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="keyword token">if</SPAN> __name__ <SPAN class="operator token">==</SPAN> <SPAN class="string token">'__main__'</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token">#Get the data and do a couple things</SPAN>
fileName <SPAN class="operator token">=</SPAN> now<SPAN class="punctuation token">.</SPAN>strftime<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"%Y-%m-%d"</SPAN><SPAN class="punctuation token">)</SPAN>
p <SPAN class="operator token">=</SPAN> multiprocessing<SPAN class="punctuation token">.</SPAN>Process<SPAN class="punctuation token">(</SPAN>target<SPAN class="operator token">=</SPAN>tbl2excl<SPAN class="punctuation token">,</SPAN> args<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">(</SPAN>countSelection<SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"E:\GIS_Testing\xyz"</SPAN><SPAN class="punctuation token">,</SPAN> fileName <SPAN class="operator token">+</SPAN> <SPAN class="string token">"_Counts.xls"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
p<SPAN class="punctuation token">.</SPAN>start<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
p<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>It just gets hung up after running p.join() and never stops. I assume it's erroring out in the new process somewhere, but I can't bring those error messages up to the parent script despite my efforts. If I don't try to run it in a separate process it doesn't error, so it's something specific to the multiprocessing, not using the TableToExcel tool itself.