I have several automated jobs that use either a startup or shutdown python script. These scripts run fine in workbench and even in the ESRI Python interpreter on the Flow machine. The issue arises when I run them from Flow. When it gets to the script it will output expected products until the exportToPDF command at which point it fails. No errors are indicated anywhere except in the Engine Log where this is displayed: WARN localhost_Engine2 393562 : Process "localhost_Engine2" ended unexpectedly. Being restarted on attempt 1…
Example of script:
import arcpy, os, sys, time, shutil
from datetime import datetime
sdpFolder = r"****OBSCURED****"
exportFolder = os.path.join(sdpFolder, "SiteDevPlanFiles")
date = time.strftime("%Y-%m-%d")
dateFolder = os.path.join(exportFolder, date)
archiveFolder = os.path.join(sdpFolder, "_Archive")
zipExportFolder = exportFolder + ".zip"
# from zipfile import ZipFile
# for file in ZipFile(zipExportFolder).namelist():
# archive previous zip
destZip = os.path.join(sdpFolder, "SiteDevPlanFiles.zip")
for x in os.scandir(exportFolder):
print(x.path)
if x.is_dir() and x.path != dateFolder:
#move old date folder to archive folder
archivedDateFolder = os.path.join(archiveFolder,date)
if not os.path.exists(archivedDateFolder):
shutil.move(x.path,archiveFolder)
#delete old copy of SiteDevPlanFiles.zip
try:
for x in os.scandir(exportFolder):
if x.is_dir() and x.path != dateFolder:
#move old date folder to archive folder
archivedDateFolder = os.path.join(archiveFolder,date)
if not os.path.exists(archivedDateFolder):
shutil.move(x.path,archiveFolder)
except:
print("fail")
if os.path.exists(destZip):
os.remove(destZip)
if not os.path.exists(dateFolder):
os.mkdir(dateFolder)
aprx = arcpy.mp.ArcGISProject(r"****OBSCURED****".aprx")
layouts = aprx.listLayouts("*")
for l in layouts:
#loop through all layouts in folder
print("-" * 50 + "\nLayout: " + l.name)
output = os.path.join(dateFolder, date+"_"+l.name)
print(output)
# export layouts with map series for phasing to pdf
if not l.mapSeries is None:
ms = l.mapSeries
if ms.enabled:
ms.refresh()
#print(f"--- {ms.pageCount} pages")
ms.refresh()
print("Test Break 1")
ms.exportToPDF(output,embed_fonts=True,
georef_info=False)
# export layouts for sitewide phasing to pdf
elif l.mapSeries is None and "Phasing" in l.name:
# exportName = os.path.join(dateFolder, date+"_"+l.name)
l.exportToPDF(output,
embed_fonts=True,
georef_info=False)
shutil.make_archive(exportFolder, 'zip', exportFolder)