I have been woking on a script that will select parcels that are within a particular ArcGIS 10.1 data driven page, create a list out of those parcels, and then populate a text element within my MXD with the parcel list.

I run this script from CMD right after I restart the machine, and it works fine. But as soon as I try to rerun it(without reboot), the script errors out. I get no error message at all other than the generic Python.exe has stopped working.

I work on a workstation with Windows 7 Pro, 3.4GHz processor with 8GB RAM, ArcDesktop 10.1, and python 2.7.

What might be the possible reasons for python to fail?

The print statements are in the script as I was trying to trouble shoot where it was crashing.

import sys
import arcinfo
import arcpy
import DatabaseFunctions

def main(args=None):
    #if args is None:
        #args = sys.argv[1:]
    #UserInput = (args[0])
    UserInput = arcpy.GetParameterAsText(0)

    except Exception as e:
        print e
    except Exception as e:
        print e

    ## Input from user
    PageNameList = [UserInput] #["1N1E03"]
    #OutputFolder = "C:\\Dan\\PythonWrestling"
    OutputFolder = "C:\\Joey"

    ## Hard coded resources
    MapFolder = "C:\\Joey"
    #MapFolder = "C:\\Dan\\PythonWrestling"
    vector = DatabaseFunctions.CreateDatabaseConnection(Database="Vector")
    mxd = arcpy.mapping.MapDocument(MapFolder + "\\SectionMap.mxd")
    layerlist = None
    del layerlist
    layerlist = arcpy.mapping.ListLayers(mxd)
    for lyr in layerlist:
        if lyr.name == "Parcels":
            PLyr = lyr
        if lyr.name == "Page":
            PGLyr = lyr
    #PLyr = arcpy.mapping.ListLayers(mxd, "Parcels")[0]
    #PGLyr = arcpy.mapping.ListLayers(mxd, "Page")[0]

    ddp = mxd.dataDrivenPages
    for pageName in PageNameList:
        ddp.currentPageID = ddp.getPageIDFromName(pageName)

        ## Create parcel list
        arcpy.MakeFeatureLayer_management(vector + "\\vector.DBO.parcels", "thingy")
        arcpy.SelectLayerByLocation_management ("thingy", "HAVE_THEIR_CENTER_IN" , PGLyr)
        sCursor = arcpy.SearchCursor("thingy",fields="PARCEL")
        parcelSetUnsorted = set()
        for row in sCursor:
            eachParcel = row.PARCEL
            if isinstance(eachParcel,basestring):
        parcelSet = sorted(parcelSetUnsorted)
        parcelListStringList = list()
        parcelListText = ""
        count = 0
        print str(len(parcelSet)) + " parcels in the set."
        for eachParcel in parcelSet:
            count = count + 1
            parcelListText = parcelListText + eachParcel + "\n"
            if count == 70:
                if (len(parcelListStringList) == 5):
                    parcelListText = parcelListText + "And more..."
                    parcelListText = ""
                count = 0
                parcelListText = ""
        if len(parcelListText) > 0:


        ## Put correct text in each text element
        elmList = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")
        upperx = .5
        uppery = 10.0
        ydelta = .75
        xdelta = .9
        ylower = .75

        for elm in elmList:
            if elm.name == "ParcelList":
                elementCount = 0
                elm.elementPositionX = -5
                for parList in parcelListStringList:
                    eachElm = elm.clone("_clone" + str(elementCount))
                    eachElm.elementPositionX = upperx + (elementCount * xdelta)
                    elementCount = elementCount + 1
                    print "--- " + parList
                    eachElm.text = parList
            #elif elm.name == "MapTitle":
                # elm.text = titleText
        ## Export as a PDF
        arcpy.AddMessage('Exporting Page')
        mxd.saveACopy(OutputFolder + "\\" + str(pageName) + ".mxd")
        #arcpy.mapping.ExportToPDF(mxd, OutputFolder + "\\" + str(pageName) + ".pdf")
except Exception as e:
    print e
del mxd

if __name__ == "__main__":

closed as off-topic by PolyGeo Jul 28 at 20:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

migrated from stackoverflow.com May 8 '14 at 18:32

This question came from our site for professional and enthusiast programmers.

  • 1
    How is it failing? What does "errors out" mean? What errors are you getting? Those messages are critical to understanding the problem, you should never omit them when asking for help. – Jonathon Reinhart May 7 '14 at 23:01
  • That is the thing. "Errors out" might have been the wrong term, the program just quits. I am getting no error messages. I just get the generic windows pop up saying that python.exe has stopped working. – user3614153 May 8 '14 at 13:50
  • Seems like a bug in the C code then. Either Python itself, or is arcpy a python or C extension? – Jonathon Reinhart May 8 '14 at 13:53
  • arcpy is a python extension that comes with ArcGIS. – user3614153 May 8 '14 at 15:07
  • 1
    Have you tried loading and running the script into the Python window in either Arc Catalog or Map? This might be useful than implementing the script from the CMD. Usually the Python window in Arc will return a more specific error, however the problem you are having sounds more unique that just a general code error. – F_Kellner May 8 '14 at 18:59

In cases like this I think you can spend a lot more time trying to troubleshoot the interaction between various aspects of your configuration (ArcGIS for Desktop, Python, Operating System, Environment Variables, etc, etc) than it takes to uninstall/reinstall ArcGIS for Desktop (with Python as part of that install) i.e. about 30 minutes.

If it is critical for you to get Python working predictably with ArcGIS 10.1 for Desktop on this machine then, if preliminary troubleshooting does not provide a solution, this step probably will.

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