I'm trying to deal with an odd crash that occurs irregularly in arcGIS's arcpy, specifically under the create random points tool.

This occurs under ArcGIS 10.1 to 10.3.

During "CreateRandomPoints", the program attempts to create by polygon a number of points in the polygon, the number dictated by a field. The problem I experience is that occasionally, upon attempting this line, python will immediately crash without giving an error code.

I accept that it's a known issue. I accept that there's nothing to be done about the crash itself, other than working around it. the problem is, i can't seem to catch the error and work around it.

I have embedded the code chunk containing


inside of a try/except block. I have set up a logic where hopefully the code would execute (and if necessary, fail) 5 times before exiting the program with an informative error. However, it only runs once, and exits the program without stating the error. (my try/except block isn't catching the error).

I have tried every error code I can think relevant, even a naked except block which to my knowledge should catch everything.

Is there some other means to catch the error? something i haven't tried yet?

  • I've fixed the workflow so that If I do have a crash, it won't cause lasting problems, but i don't know if I've solved the crash. – Faydey Dec 5 '15 at 23:44

The error might be from how you're formatting the arguments with that empty argument between shape and field. You could try this instead:

arcpy.CreateRandomPoints_management(wkspc, outshape, shape, number_of_points_or_field=field)

Otherwise, I don't know if this would work for you, but I have a tool I made that creates random points too. You can download it here:

Generate Random Points Toolbox

View the Source Code

You could then use this in your Python script by doing the following:

arcpy.GenerateRandomPoints_GenerateRandomPoints(input_polygon, "YES", "fieldname", "#", 40, 2000, "KEEP_ALL", output)

#where parameters for the tool are:
arcpy.GenerateRandomPoints_GenerateRandomPoints(Input_Polygon_Feature_Class, Use_Field_for_Number_of_Random_Points, {Field_with_Number_of_Random_Points}, {Number_of_Random_Points}, Minimum_Distance_Between_Points, Maximum_Attempts, Keep_Point_Attempts, Output_Point_Feature_Class)

Here's a screenshot of the parameters: enter image description here

| improve this answer | |
  • in arcpy.createrandompoints_management(), the empty argument is for the "extent" that would be used if the input shapefile wasn't populated. It is, so that argument is meaningless. That said, I tested your tool versus the arcpy tool.... In both cases, the input dataset (limited to 3 states... so a subset of the total data) was loaded in memory prior, and the arcpy tool took 15 seconds while your tool tool 350 seconds. I think your tool moves the data to memory (again), so the test may be a bit biased against your tool – Faydey Dec 5 '15 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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