Select to view content in your preferred language

Python For Loop Causes buffer overrun to fail

813
3
10-20-2010 01:19 PM
DanielSmith
Frequent Contributor
Hello All,

I am having some weird issues with python.

Background:  What i have done is use python to automate compliance monitoring for a project site. the only parameters that we change in the script is the root reporting directory. the script copies and pastes a template GDB (that contain standard reporting datasets) and access several raster data sets for the analysis (these rasters are within the root reporting directory).

Problem: After discussion it was decided that the template GDB and the standard reporting grids need to be altered and the analysis run retroactively on all previous analysis dates (about 60 dates total). So i extended my script with some of the os methods to build a list of all the directories that need to be reanalyzed. No big deal there. The code to build the list of root reporting directories works fine and all i do is pass the reporting directory (from the list) to my compliance monitoring script (actually its all in the same script i just define a function at the beginning of the script, the function being the compliance monitoring script e.g. def CompMon (root reporting directory) with all analysis gp tasks coded below)

Error:Buffer over run on the 10th iteration of the loop. At the end of each iteration I delete the gp object and all variables with the "del" statement to help manage space.
0 Kudos
3 Replies
DonovanCameron
Deactivated User
I can't find the forum that speaks to this directly, but are you running out of memory?

When using python to generate buffers, especially when using iteration/lists, there is a bug that causes python to have a memory leak.

This is suppose to be corrected in the up-and-coming SP1 for ArcGIS10
0 Kudos
DanielSmith
Frequent Contributor
interesting... so maybe i should manually define my list of directories maybe as a tuple to avoid this bug? I will still be iterating through the tuple though so maybe not a good solution... what if i generate a standalone module and call it rather than defining the module with in the script? still iterating through the tuple though.....darn...... i will test and let you know how it goes.....thanks for your time...
0 Kudos
Luke_Pinner
MVP Regular Contributor
Try running your original script in a separate process from the script that does the looping, passing the directory to process to the original script each loop:

#Master script to loop

def runcmd(cmd, format='s'):
    import subprocess
    proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    stdout,stderr=proc.communicate()
    exit_code=proc.wait()
    return exit_code,stdout,stderr

for dir in <list of directories>:
    cmd ='%s %s %s' % (<path to python>, <path to your script>, dir)
    exit_code,stdout,stderr = runcmd(cmd)
0 Kudos