I have three scripts running simultaneously that processes raster data in several directories. The problem I am encountering is that ArcGIS is creating a temporary grid file called 'Extract_recl1' when the Extract by Mask (Spatial Analyst) tool is called. The temporary file is created in a directory where it is looking for raster data. Seeing that I have several scripts running simultaneously, there is occasionally conflict where one script trys to run Extract By Mask and encounters 'Extract_recl1', which was created by Extract by Mask running in a different script. This is the error I receive:

ExecuteError: ERROR 010429: Error in GRID IO: CellLyrCreateInternal: Directory f:\mydirectory\reclass_new_classes\extract_recl1  already exists.
ERROR 010302: Unable to create the output raster: F:\mydirectory\reclass_new_classes\Extract_recl1
ERROR 010067: Error in executing grid expression.
Failed to execute (ExtractByMask).

I have tried to handle this situation by saving the raster object with a unique name to a temp directory and deleting the file upon completion:

# Extract by mask
reclass_clp = ExtractByMask(reclass, mask_raster_temp)
reclass_clp_temp = random_name_generator(temp_ws, "reclass_clp_temp", ".tif") # This is a function that generates a unique output name

# Do some processing...


I have also set the overwriteOutput environment to True.

arcpy.env.overwriteOutput = True

However, neither of these seem to have any effect. What is the best way to handle temporary files created by Extract By Mask (Spatial Analyst)?

In other words, is there a way to force Extract by Mask to generate a unique name for the temp grid 'Extract_recl1'?

  • I've never seen these left over after the script runs to completion (esp. if you have delete running on them). Are you sure the script isn't ending prematurely? I just noticed that you are saving the same output you are trying to delete. Is that really intended? Commented Dec 22, 2015 at 15:16
  • @jbchurchill These temp grids are generated and deleted automatically at the completion of each iteration. The conflict occurs when another script accessess raster data from the same directory and produces this'Extract_recl1' file at the same time. That is to say, two scripts are creating this temp file simultaneously and there is no way to control the output location or the name.
    – Aaron
    Commented Dec 22, 2015 at 15:57
  • The error help says its a problem with the .hdr file. support.esri.com/fr/knowledgebase/techarticles/detail/36717 Commented Dec 22, 2015 at 16:13
  • @Luke. Not abandoned, just off the radar.
    – Aaron
    Commented Aug 3, 2016 at 3:58

1 Answer 1


The Extract By Mask tool honours the Scratch Workspace environment. Try setting a different arcpy.env.scratchWorkspace for each script run with the python tempfile.mkdtemp function.

import tempfile, shutil
import arcpy
from arcpy.sa import *

tmpdir = tempfile.mkdtemp()
arcpy.env.scratchWorkspace = tmpdir

reclass_clp = ExtractByMask(reclass, mask_raster_temp)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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