Skip to main content

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)

 

I have exact same problem.
It works fine in FME Form but not in FME Flow. It also works fine on my machine (with Windows 11) in Windows scheduler where I have a runner.bat that runs a pythonfile with the pythoncode below.

But it does not work on a Windows Server (We have upgraded from Windows Server 2019 to 2022 but it did not make any difference).
I have tried with ArcGIS Server on the server, and with only ArcGISPro (3.3) on the server (with MicrosoftEdgeWebView2RuntimeInstallerX64 installed).
I also tried with a older version of ArcGISPro.

I have all admin permissions on the folders and in task scheduler.

So, the question is what can cause this arcpy.exportToPDF to fail? and without any errormessages.
 

import arcpy, os

def main():
    print(f"1")
    # Ange sökvägar
    prjPath = os.path.normpath(r'C:\temp\fme')
    outputPath = os.path.normpath(r'C:\temp\fme\testoutput')
    print(f"2")
    path = os.path.join(prjPath, 'Test_PDFutskrift.aprx')
    print(f"2.1")

    # Öppna ArcGIS Pro-projektet
    p = arcpy.mp.ArcGISProject(path)
    print(f"3")

    # Lista av layoutnamn
    layoutNames = o'A3', 'A2']
    for name in layoutNames:
        # Hämta layout
        print(f"4")
        layouts = p.listLayouts(name)
        if len(layouts) == 0:
            print(f"Layout {name} finns inte i projektet.")
            continue
        lyt = layoutse0]

        # Sökväg för PDF-export
        pdfPath = os.path.join(outputPath, f"{name}.pdf")
        print(f"Försöker exportera {name} till {pdfPath}...")
        
        # Exportera till PDF
        try:
            lyt.exportToPDF(pdfPath)
            print(f"Lyckades exportera {name} till {pdfPath}.")
        except Exception as e:
            print(f"Misslyckades med att exportera {name} till PDF: {e}") 
    
if __name__ == "__main__":
    main()


Hi ​@dalneberg and ​@joshmon,

 

Can you provide the versions of FME Form/Flow and ArcGIS Server you’re using? Here are a few things to check:

Please let me know if there is any other relevant information about the environment that would help us reproduce this issue.

 

—Dylan


Hi ​@dylan.at.safe 

FME Form 2024.2.1, FME Flow 2024.2.1
ArcGIS Server 11.3.
See also below that i tested with ArcGISPro 2.9, 3.3 and 3.4 on the machine.

This is from the fmeprocessmonitorengine.log:

localhost_Engine1   Started translation command: 'Systemgruppen_scripts\Test_export_arcpy\Test_export_arcpy.fmw'
localhost_Engine1   INFORM: An ArcGIS license is already checked out. The product checked out is 'ArcServer'
localhost_Engine1   
localhost_Engine1   Reading...
localhost_Engine1   Emptying factory pipeline
localhost_Engine1   Translation was SUCCESSFUL with 0 warning(s) (0 feature(s) output)


I have tested allmost every versions of Python, it makes no difference.

Yes, fme flow service account have permission to write to the destinationfolder.

I have done some tests do run the python-script from the Task Scheduler and this is the result:

It works on my machine (with Windows 11) in Windows scheduler (with option: Run whether user is logged in or not). (I have a runner.bat that runs a pythonfile.)

But it does not work on a Windows Server (We have upgraded from Windows Server 2019 to 2022 but it did not make any difference).

On this Windows server it only works to run when i run it right in the commandtool, or in a windows task scheduler with the option: Run only when the user is logged on.

I have tried with ArcGIS Enterprise 11.3 on the server, and also tried with only ArcGISPro (2.9, 3.3 and 3.4) on the server. All with MicrosoftEdgeWebView2RuntimeInstallerX64 installed (test is done with version 133.0.3065.92 and 134.0.3124.51).

The thing is that it worked well until dec 2024/jan 2025, we upgraded both FME Flow and ArcGIS in that period.


 


Hi ​@dylan.at.safe 

FME Form 2024.2.1 and FME Flow 2024.2.1

I get the following message in the fmeprocessmonitorengine.log:

localhost_Engine1   Started translation command: 'Systemgruppen_scripts\Test_export_arcpy\Test_export_arcpy.fmw'
localhost_Engine1   INFORM: An ArcGIS license is already checked out. The product checked out is 'ArcServer'
localhost_Engine1   
localhost_Engine1   Reading...
localhost_Engine1   Emptying factory pipeline
localhost_Engine1   Translation was SUCCESSFUL with 0 warning(s) (0 feature(s) output)


Yes, and I have tested almost every version of python.

Yes, the FME Flow service account have permission to write to the destination folder.

I have done tests do run the script in the Task scheduler and this is the results:

It works on my machine (with Windows 11) in Windows scheduler (with option: Run whether user is logged in or not). (I have a runner.bat that runs a pythonfile.)

But it does not work on a Windows Server (We have upgraded from Windows Server 2019 to 2022 but it did not make any difference).

On this Windows server it only works to run when i run it right in the commandtool, or in a windows task scheduler with the option: Run only when the user is logged on.

I have tried with ArcGIS Server on the server, and also tried with only ArcGISPro (2.9, 3.3 and 3.4) on the server. Both with MicrosoftEdgeWebView2RuntimeInstallerX64 installed (test is done with version 133.0.3065.92 and 134.0.3124.51).

I have all admin permissions on the folders and in task scheduler.

 


Reply