8

i am using a python script that's eliminating small polygons from a feature class. this script creates temporary feature classes with fixed (hardcoded) names in the "in_memory" workspace. example:

arcpy.CopyFeatures_management("in_fc","in_memory/item_a")

it's a fairly reusable script, so i use it at many points in a geoprocessing chain.

am i in danger, that the same script called twice from different processes (at the same time) will have a conflict at, for example "in_memory/item_a" ? or are the "in_memory" workspaces seperate for each process?

i am using ArcInfo 10.0.

asked Oct 12, 2012 at 9:58

1 Answer 1

8

To test out your question, I wrote up a quick script that I ran two copies of simultaneously- one as a script tool in ArcMap and one in Pythonwin. Somewhat to my surprise, I was unable to run them at the same time because the "in_memory" workspace was shared. There is a way around this, however. You can add in an output check to determine if the file in memory exists, and name it something else if so:

i=0
check = 0
while check == 0:
 memoryFeat = "in_memory" + "\\" + "testMemoryFeature" + str(i)
 if arcpy.Exists(memoryFeat):
 i+=1
 else:
 check = 1

This will attempt to name your in memory feature testMemoryFeature0. If that memory feature already exists, it will attempt to name it testMemoryFeature1, and so on until it finds a name that will suffice.

answered Oct 12, 2012 at 14:56
2
  • 7
    You can also use arcpy.CreateUniqueName function. Commented Oct 12, 2012 at 15:48
  • Very handy! I didn't know this existed. Commented Oct 12, 2012 at 15:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.