Attachment Manager hangs when run in command line

08-11-2022 04:49 AM
Occasional Contributor

I'm working on a script that I intend to run as a Windows service. The purpose of the script is to watch a folder for .msg email files, parse out their contents when they come in, and put a point on the map with all the extracted attributes. If there is an attachment, the script then attaches it to the newly created feature. Everything works great when testing in a notebook in Pro, but I get a curious issue when I test it running as a standalone script from Windows command line. What I'm experiencing is the script gets to the line where it actually adds the attachment, then it hangs until I do a keyboard interrupt. 50% of the time it will continue and finish processing the email before exiting, 30% of the time it just exits, and 20% of the time it will continue and process any additional emails without issue. It's great that I can get it going with a keyboard interrupt, but that's not a workable solution for what's supposed to be an automated process. Again, I do not experience this issue in Pro. I am making sure to run it calling the same Python environment that I'm using in the Pro project, as the module that I'm using to process the .msg files is not in the default Python environment.

Here's the relevant code snippet:




#create feature
newFeature = features.Feature.from_dict(msgDict)
#add feature to digsafe layer
newCall = digSafe.layers[0].edit_features(adds = [newFeature])
#if email has attachments, add to feature
if len(attachments) > 0:
    filePath = attachments[0].save()
    oid = newCall['addResults'][0]['objectId']
    #script makes it to here then hangs




Has anyone else experienced this issue? Is there an easy solution, or is this a software bug? I'm using Pro 3.0 pointing to a service on Portal 10.9.1 that references an enterprise geodatabase.

0 Kudos
1 Reply
Occasional Contributor


I've also tried running this in the Python Window by copying and pasting my code into the window. This results in the same behavior, where the script hangs on the line where the attachment is added to the newly created feature. A keyboard interrupt will exit the code, and the email file it hangs on and any queued files will be processed correctly.

To further test this, I copied all of my code into a new Notebook in Pro, making sure all functions and blocks of code appear and run in the same order as the standalone script. Running it through the Notebook, I experience no issues. Clearly there's a difference between the different run modes, but I can't figure out what it is.

0 Kudos