I have a python script that creates a temporary feature class, creates a feature layer from the temporary feature class, uses the feature layer, then deletes the feature layer and the feature class. When I try to publish the python script as a Geoprocessing service I get an ERROR saying that my project contains a broken project data source on my temporary feature layer. So far my work around is to leave the temporary feature class in my workspace. Is there a way to delete it before the process completes? Here is the code snippet that generates the error:

acadian_holder_fpath = "\\\\my_server\\GIS\Geodatabases\\Acadian_Holder.gdb\\Acadian_Holder_Dataset\\Acadian_Holder"
xxcrown_fpath = "\\\\my_server\\GIS\\Geodatabases\\Temp_WorkSpace.gdb\\xxholder_src"
arcpy.analysis.Select(acadian_holder_fpath,xxcrown_fpath,"LOC in ('BB','BC','BM','IQ','JC','JN','JS','JW','PH','QB','RB','RG','RS','SQ','SV','UG')")
dnr_regions_fpath = "\\\\my_server\\GIS\\Geodatabases\\Acadian.gdb\\dnr_regions"
xxregions_fpath = "\\\\my_server\\GIS\\Geodatabases\\Temp_Workspace.gdb\\xxregions_src"



at_road_network_fpath = "\\\\my_server\\GIS\\Geodatabases\\connection_to_my_sde.SDE\\AT_Road_Network"

# Use select by location instead of intersect so we get the entire road if it exits crown land.

at_road_network_flayer = arcpy.management.MakeFeatureLayer(at_road_network_fpath,"at_road_network_flayer")

xxregions_flayer = arcpy.management.MakeFeatureLayer(xxregions_fpath,"xxregions_flayer")

# Select YTD roads

where_clause = "Region = 1 or Region = 3 or Region = 4"
arcpy.management.SelectLayerByAttribute(xxregions_flayer, "NEW_SELECTION", where_clause)
arcpy.management.SelectLayerByLocation(at_road_network_flayer, "INTERSECT", xxregions_flayer)

# Do stuff with at_road_network_flayer

# Delete the temporary feature class

del xxregions_flayer

2 Answers 2


Consider using the in memory workspace. It's a lot faster than writing to disk and should solve your read/write locking.

For example:

xxregions_flayer = arcpy.management.MakeFeatureLayer("in_memory","xxregions_flayer")

When you are ready to delete your temporary feature class, call

  • Thanks for your suggestions. I like using the in memory workspace since I need to do several selections by location and by attribute on that feature layer. The in_memory option really sped things up. Jun 6, 2014 at 14:32

I'd do a few things here.

1) Dont use delete at the end. There isn't really any point that I can see as its just the feature layer you're deleting. Once the GP Service is finished executing, thats it, its done. Clean up happens, so theres no need to delete anything.

2) Dont use MakeFeatureLayer. Just use layers inside your script. By using a layer you can skip the MakeFeatureLayer call. Sure it might only be 0.4 seconds to execute that, but why do that needlessly when you can just use layers to begin with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.