Question

Arcpy in python caller crashes ArcGIS Pro

  • 22 March 2024
  • 4 replies
  • 53 views

Badge +5

Hi,

 

I wrote some code to copy feature classes from one gdb to another.

Everything runs fine through python, but it fails when I try adding it to a python caller - Specifically, it crashes ArcGIS Application. I have no idea what’s going wrong as I get no error message, only this screen:

The odd part is that it manages to delete a layer and then copy the new one across before crashing:

Here’s the code i’m trying to run. Apologies in advance for the mess, it’s not my strong point!

import fme
import fmeobjects
import arcpy
import os
import fnmatch
from arcpy import env


class FeatureProcessor(object):
"""Template Class Interface:
When using this class, make sure its name is set as the value of the 'Class to Process Features'
transformer parameter.
"""

def __init__(self):
"""Base constructor for class members."""
pass

def has_support_for(self, support_type: int):
"""This method is called by FME to determine if the PythonCaller supports Bulk mode,
which allows for significant performance gains when processing large numbers of features.
Bulk mode cannot always be supported.
More information available in transformer help.
"""
return support_type == fmeobjects.FME_SUPPORT_FEATURE_TABLE_SHIM

def input(self, feature: fmeobjects.FMEFeature):
"""This method is called for each feature which enters the PythonCaller.
Processed input features can be emitted from this method using self.pyoutput().
If knowledge of all input features is required for processing, then input features should be
cached to a list instance variable and processed using group processing or in the close() method.
"""



arcpy.env.workspace = r"C:/Sewer_AssetPackage.gdb"
outGDB = r"C:/AssetPackage7.gdb/"


fcs = arcpy.ListFeatureClasses()
tables = arcpy.ListTables()
ds_list = arcpy.ListDatasets()



for fc in fcs:
arcpy.Delete_management(outGDB+fc)
print("{0} has been deleted".format(fc))
arcpy.management.Copy(fc, outGDB+fc)
print("{0} has been copied".format(fc))

for t in tables:
if t == 'WINGS_RELATIONSHIPS':
arcpy.Delete_management(outGDB+t)
print("{0} has been deleted".format(t))
arcpy.management.Copy(t, outGDB+t)
print("{0} has been copied".format(t))



for ds in ds_list:
for FC in arcpy.ListFeatureClasses("*","",ds):
if ds == 'UtilityNetwork':
arcpy.Delete_management(outGDB+ds+'/'+FC)
print("{0}/{1} has been deleted".format(ds,FC))
arcpy.management.Copy(FC, outGDB+ds+'/'+FC)
print("{0}/{1} has been copied".format(ds,FC))
elif ds == 'SewerOther':
arcpy.Delete_management(outGDB+ds+'/'+FC)
print("{0}/{1} has been deleted".format(ds,FC))
arcpy.management.Copy(FC,outGDB+ds+'/'+FC)
print("{0}/{1} has been copied".format(ds,FC))




self.pyoutput(feature)

def close(self):
"""This method is called once all the FME Features have been processed from input()."""
pass

def process_group(self):
"""This method is called by FME for each group when group processing mode is enabled.
This implementation should reset any instance variables used for the next group.
Bulk mode should not be enabled when using group processing.
More information available in transformer help.
"""
pass

 

I read that someone had a similar issue (not in FME) and it was due to declaring the arcpy.env.workspace variable. When I remove this I have no idea how to use the list_featureclasses/datasets/tables/ function.

 

Any help would be much appreciated!

 

Many thanks,

 

Sam

 

Form version: 2023.1

Python version ESRI ArcGIS Python 3.7+/3.9


4 replies

Userlevel 5
Badge +29

Couple of questions to help diagnose:

  • Is the one that it fails on the first one you copy?
  • Is that a FC, Table or Dataset?
  • Does manually copying the dataset between GDBs work? Does it also work running the Python in ArcPro?
  • Does the failing FC have any joins or relationships?
Badge +5

Hi @hkingsbury,

Thank you for the reply.

To answer a few of your questions:

  • No it manages to copy the first feature class (Which there is only one of). I tried removing the next chunk of code in sequence, but the same error occurs.
  • I’m copying tables, feature classes and feature classes that are located inside feature datasets.
  • Manually copying the GDB’s works and using the exact same code within Python in ArcGIS pro works
  • No, there’s no joins on the feature class

The script has 3 for statements that copy data into a new gdb. The statements handle:

  1. FC’s in the geodatabse
  2. Table in GDB
  3. FC’s within a feature dataset located inside the GDB

I have tried changing the order of the FC’s and the script manages to copy the first item, but consistently crashes before doing the next one.

 

Many thanks,

 

Sam

Userlevel 5
Badge +29

I just ran your code against a test GDB and it worked fine on my side.

What errors are you getting in the FME log?

Badge +5

Hi @hkingsbury ,

There is no error code. I get an error saying that ArcGIS has crashed: and the workbench stops running

 

It’s worth noting that I pushed the exact same workbench containing the code into FME Flow and it has worked. It’s possible that there is some sort of error with the FME form or ArcGIS install maybe? Although I have quite a few other workbenches that use arcpy fine.

 

Happy to close this one off as it works fine in FME Flow :)

 

Many thanks,

 

Sam

 

Reply