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
digSafe.layers[0].attachments.add(oid,filePath)
os.remove(filePath)
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.