I developed a script for ArcGIS Pro which performs 4 heavy downloads. To speed-up the process, I delegated the download process to 4 worker threads and wait for them complete in order to continue the geoprocess operations. During the download process, I use the arcpy.AddMessage() function to give some feedback.
Everything works as expected when I execute de code as a python standalone script, including the feedback messages. However some messeges did not show when running the script in ArcGIS Pro.
I suspect that the worker threads are writing the messages in somewhere else. To test my thoughs, I wrote the following script:
import concurrent.futures
import threading
import arcpy
def add_message_wrapper(message):
arcpy.AddMessage('Thread {0} says: {1}'.format(threading.current_thread().getName(), message))
if __name__ == '__main__':
add_message_wrapper('Hello addMessage')
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [executor.submit(add_message_wrapper,
'Hello addMessage from a worker thread') for i in range(6)]
for future in concurrent.futures.as_completed(futures):
pass
add_message_wrapper('Back to main...')The output as a standalone python script:
Thread MainThread says: Hello addMessage
Thread ThreadPoolExecutor-0_0 says: Hello addMessage from a worker thread
Thread ThreadPoolExecutor-0_0 says: Hello addMessage from a worker thread
Thread ThreadPoolExecutor-0_0 says: Hello addMessage from a worker thread
Thread ThreadPoolExecutor-0_1 says: Hello addMessage from a worker thread
Thread ThreadPoolExecutor-0_0 says: Hello addMessage from a worker thread
Thread ThreadPoolExecutor-0_2 says: Hello addMessage from a worker thread
Thread MainThread says: Back to main...
The output as a script in ArcGIS Pro:
Messages
Start Time: sexta-feira, 1 de fevereiro de 2019 11:49:40
Running script testAddMessage...
Thread Dummy-1 says: Hello addMessage
Thread Dummy-1 says: Back to main...
Completed script testAddMessage...
Succeeded at sexta-feira, 1 de fevereiro de 2019 11:49:45 (Elapsed Time: 4,80 seconds)
So, how can I get the messages from worker threads sent to ArcGIS Pro output?