Python tool causes arcmap.exe not to close - BUG ?

667
2
02-12-2013 06:06 AM
SzymonPiskula
New Contributor
Hi,

I wrote a very simple geoprocessing python script that after running it and closing ArcMap, the ArcMap.exe process never ends/closes. As a result sometimes it holds locks on SDE featureclasses etc. I've tried this on ArcMap 10 SP5 (on Win7 and WinXP) and ArcMap 10.1 SP1 (on Win7) and it occurs on all configurations. Here is the tool's code:

import arcpy

fc = arcpy.GetParameterAsText(0)

arcpy.AddMessage("FC:"+str(fc))

featcur = arcpy.SearchCursor(fc)
#.next() causes problem - arcmap.exe process does not disappear after appilcation window is closed 
f_row = featcur.next()

arcpy.AddMessage("DONE")

del f_row
del featcur

arcpy.AddMessage("Mem released")


The problem occurs only for Feature Classes from SDE. In particular I tried MS SQL Express 2005 + Direct Connect, also had the same problem with Oracle and PostgreSQL. It seems OK for .gdb features. The problem seems not to occur with empty SDE feature classes. Also it seems that the problem does not occur under ArcCatalog.

To reproduce:
1.Make sure no ArcMap is running (check under Task Manager / Processes tab)
2.Start clean ArcMap session
3.Open cursorBug tool from the attached CursorTest.tbx
4.Run the tool with any non-empty SDE feature class
5.Once the tool finishes close it and close ArcMap.
6.Check Task Manager / Processes tab. ArcMap.exe prcoess stays there and never closes

The 'cursorOk' tool is just for reference to demonstrate that it all works as expected if the  'f_row = featcur.next()' statement is not present in the code.

Can I have any feedback on this? Or am I missing something? Is there a better way of releasing resources?
Thanks,
Szymon
Tags (2)
0 Kudos
2 Replies
ChrisFox3
Occasional Contributor III
Szymon,

Thank you for your work on this one and narrowing down the problem. This is a bug and I have gone ahead and logged it into out system, NIM089008.

As a couple of workarounds, if you are at 10.1 I found that the new Data Access module cursors did not have the same issue:

http://resources.arcgis.com/en/help/main/10.1/#/SearchCursor/018w00000011000000/

In addition, I found that if I ran your script tool in the background, the problem did not occur either. I apologize for the inconvenience of this issue.
0 Kudos
MichaelVolz
Esteemed Contributor
Are these locks the same as connections to SDE still existing in the Process Information table of SDE?

I ask because I have a python script run in ArcGIS Desktop v10.0 that searches through a polygon feature class for bad data items that might crash a downstream database script.  Unless I close out of the python script, a SDE process still lingers in the Process Information table of SDE.

Based on this post, I upgraded the python script to run in ArcGIS Desktop v10.1 using arcpy.da.SearchCursor.

Unfortunately, after running this updated python script, the SDE process still lingers in the Process Information table of SDE.

Is this the same issue as the original post?
0 Kudos