1

Using arcpy and reclassify, I'm trying to run a loop reclassifying the same dataset accoding to different values. I've reduced this example to three loops, the original is much longer.

import arcpy
from arcpy.sa import *
arcpy.env.overwriteOutput = True

reclass_values = [10, 20, 30]
reclass_output = [path1, path2, path3] # the paths are localfolders that get synchronized via dropbox

for x in range(0,3):
    recl = Reclassify(in_raster, reclass_field, RemapValue([[0,0],[1,reclass_value[x]]]))
    recl.save(reclass_output[x])

Everytime I run the code, the second part of this code (saving it) randomly doesn't work giving the following error message:

Unable to remove directory. Possible causes:
1- Not owner of the directory
2- Another person or application is accessing this directory

I'm trying to understand what is happening, and this is the way I see it: Since the "Reclassify" command does't have a built in output folder, arcpy uses the workspace as a cash for the temporary files. It names the files according to its own syntax, a mixture of the command name ("reclassify") and the filename.

I thought the error might have to to do with a conflict of filenames in the workspace, since looping the commands might result in arcpy trying to overwrite temporary files that are still locked. So I added a delete function in order to clear the workspace and after every round. Doesn't help. Then, I've tried assigning a different workspace in every loop. Doen't help. I added ClearWorkspaceCache_management(), still the same. Here is a code example with these three methods implemented.

for x in range(0,3):
    newworkspace = workspace + "\\" + str(y) # i made sure these folders exist beforehand
    arcpy.env.workspace = newworkspace        
    recl = Reclassify(in_raster, reclass_field, RemapValue([[0,0],[1,reclass_value[x]]]))
    recl.save(reclass_output[x])
    files = os.listdir(newworkspace)
    for f in files:
          full_path = os.path.join(newworkspace, f)
          arcpy.Delete_management(full_path)
    arcpy.ClearWorkspaceCache_management()

Is there another arcpy cash that I'm overlooking? Can somebody point out the direction in which I can search for the problem? Its driving me crazy!

This is what I get with traceback and arcpy.GetMessages(2)

Exception happened during processing of request from ('127.0.0.1', 57291) Traceback (most recent call last): File "C:\Python27\ArcGIS10.1\lib\SocketServer.py", line 284, in _handle_request_noblock self.process_request(request, client_address) File "C:\Python27\ArcGIS10.1\lib\SocketServer.py", line 310, in process_request self.finish_request(request, client_address) File "C:\Python27\ArcGIS10.1\lib\SocketServer.py", line 323, in finish_request self.RequestHandlerClass(request, client_address, self) File "C:\Python27\ArcGIS10.1\lib\SocketServer.py", line 641, in init self.finish() File "C:\Python27\ArcGIS10.1\lib\SocketServer.py", line 694, in finish self.wfile.flush() File "C:\Python27\ArcGIS10.1\lib\socket.py", line 303, in flush

self._sock.sendall(view[write_offset:write_offset+buffer_size])

error: [Errno 10053] Eine bestehende Verbindung wurde softwaregesteuert durch den Hostcomputer abgebrochen Traceback (most recent call last): File "C:\Python27\ArcGIS10.1\lib\SocketServer.py", line 284, in _handle_request_noblock self.process_request(request, client_address) File "C:\Python27\ArcGIS10.1\lib\SocketServer.py", line 310, in process_request self.finish_request(request, client_address) File "C:\Python27\ArcGIS10.1\lib\SocketServer.py", line 323, in finish_request self.RequestHandlerClass(request, client_address, self) File "C:\Python27\ArcGIS10.1\lib\SocketServer.py", line 641, in init self.finish() File "C:\Python27\ArcGIS10.1\lib\SocketServer.py", line 694, in finish self.wfile.flush() File "C:\Python27\ArcGIS10.1\lib\socket.py", line 303, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size]) error: [Errno 10053] Eine bestehende Verbindung wurde softwaregesteuert

durch den Hostcomputer abgebrochen

Exception happened during processing of request from ('127.0.0.1', 57294)

  • please share some code, that would be helpful in understanding the problem. Also, have you tried arcpy.env.overwriteOutput = True. – Surya Jan 16 '15 at 12:55
  • Ok, I've updated the post with a mmore complete example. I had already set the: arcpy.env.overwriteOutput to True – Ratnanil Jan 16 '15 at 13:17
  • Please provide whole Traceback message too. You haven't shared that how you are removing the directory and what is the path1, path2... is it a local path or network path? – Surya Jan 16 '15 at 13:31
  • I've updated the post. the path1, path2, path3 are local folders but they get synced with dropbox. I've tried adding the traceback message, but since this is my first time I'm not sure if I've done this correctly – Ratnanil Jan 16 '15 at 14:11
  • would it be a timing issue? - if the recl instance was still writing to disc while the loop continues? If so, would setting recl=None after the save release it for a new instantiation of the object? – fluidmotion Jan 16 '15 at 14:18

Your Answer

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

Browse other questions tagged or ask your own question.