ERROR

Print statements inside an in-process script tool cause error

Last Published: April 25, 2020

Error Message

Running in-process python scripts in ArcToolbox produces the following error:

"<type 'exceptions.IOError'>: [Errno 9] bad file descriptor".

Cause

Print statements inside a loop within the script; for example, when using Cursors.

Code:
import arcgisscripting
gp = arcgisscripting.create(9.3)

for x in range(1,2500):
gp.addmessage(str(x)) # this line only necessary to track where it fails
print x

Solution or Workaround

The following are known solutions to this issue:

  • Comment out or remove the print statements.
  • Wrap the print statements in a try/except, such as in the example below:

    Code:
    try:
    print "some statement"
    except IOError:
    pass

Article ID:000010230

Software:
  • ArcMap 9 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options