MakeFeatureLayer fails in multiprocessing python

2255
14
07-21-2014 03:42 AM
GeorgZweyer
New Contributor II

Hello everyone,

--- Update -------------------------------

See later posts for specific problem description.

i try to use python multiprocessing to do some processing on chunks of a feature class. I changed the third example from this esri post: Multiprocessing with ArcGIS – Approaches and Considerations (Part 1) | ArcGIS Blog

If i set the poolsize to 1 it runs correctly but if i use more than one process "MakeFeatureLayer" throws a "Cannot open file" or "Dataset does not exist or is not supported" error most of the time for every process but the first one. (I use "MakeFeatureLayer" on three different Files in every process and it fails at one of them for sure)

It seems to be an error related to accesing the same file at the same time out of different processes, because inserting a waiting time befor starting the "MakeFeatureLayer" methods seems to work. Because this problem is not mentioned in the esri post or somewhere else in the www i think it must be my mistake but i just do the same thing like esri in their third example of the mentioned post 😕 The only thing mentioned in the blogpost is that you cannot use multiprocessing to update data in a gdb but "MakeFeatureLayer" needs only read access, doesn't it?

def worker(ranges):

    i = ranges[0]

    j = ranges[1]

    try:

        arcpy.AddMessage("started processing thread ")

        arcpy.AddMessage(ranges)

        arcpy.CheckOutExtension("3D")

##        time.sleep(1*(ranges[2]-1))

        samples=arcpy.MakeFeatureLayer_management(Input_Point_Features, "point_layer{0}".format(i), "OBJECTID >= {0} AND OBJECTID <= {1}".format(i, j))

anyone some suggestions?

thx

Tags (2)
0 Kudos
14 Replies
JoshuaBixby
MVP Esteemed Contributor

Does enabling or disabling 'Background Processing' make a difference?

Since the script works fine from a Windows command line, and even when ArcScene is open, I am wondering if there is a communication issue between ArcScene and the process it is spawning, if Background Processing is enabled.

0 Kudos
GeorgZweyer
New Contributor II

It runs without background processing. I tried it with now, but i dont get my console output anymore, so its hard to tell if any error occurs. Maybe i can write to a log file, but i dont think enableing background processing would better anything 😕

But that was a good idea background processing often screws up everything

0 Kudos
GeorgZweyer
New Contributor II

After a few test runs i seem to have found the cause of the problem. Well not really the cause of the problem but at least the case were it can occur.

As i mentioned in my last post the only difference between starting it from comandline or from ArcScene is that i use Layers as input if i start it from ArcScene. So i made a few runs from inside ArcGis with only "true files" as input and no error occured so far!

So the problem seems to be: Error in "MakeFeatureLayer" on layer while multiprocessing in python. (Well also on raster layer and "CopyFeatures/Raster" also throws ErrorExecutingFunction sometimes)

0 Kudos
ChrisMathers
Occasional Contributor III

Does this have to be run from within ArcScene? Can you just run it stand alone with Scene closed?

0 Kudos
GeorgZweyer
New Contributor II

No that's not really a must have. I just wanted to make it possible to use layers with selections as input. Also running it from ArcScene but without using layers as input seems to work fine. Well i think i just have to get along with that.

0 Kudos