Hi All,
Really simple script attached to a toolbox tool:
- has a wrapper class to convert logging to arcpy.AddMessage.
- no input or output parameters
- has a main function that adds a single message to the window
- imports arcpy and logging only
- runs successfully the first time
- fails every time after that until the arcmap/arccatalog app is restarted
- ArcGIS Desktop 10.6.1
Zip file attached with script and toolbox. Here's the script:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> logging
<SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">AddMessageHandler</SPAN><SPAN class="punctuation token">(</SPAN>logging<SPAN class="punctuation token">.</SPAN>Handler<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">emit</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> record<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
log_entry <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>record<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>log_entry<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">main</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
logging<SPAN class="punctuation token">.</SPAN>debug<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"----this is a test----"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> __name__ <SPAN class="operator token">==</SPAN> <SPAN class="string token">'__main__'</SPAN><SPAN class="punctuation token">:</SPAN>
logging<SPAN class="punctuation token">.</SPAN>basicConfig<SPAN class="punctuation token">(</SPAN>level<SPAN class="operator token">=</SPAN>logging<SPAN class="punctuation token">.</SPAN>DEBUG<SPAN class="punctuation token">)</SPAN>
root_logger <SPAN class="operator token">=</SPAN> logging<SPAN class="punctuation token">.</SPAN>getLogger<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
root_logger<SPAN class="punctuation token">.</SPAN>addHandler<SPAN class="punctuation token">(</SPAN>AddMessageHandler<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
main<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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>First run success:

Subsequent runs fail:
