import arcpy with arcpy.da.SearchCursor( 'C:/Temp/foo.shp' , [ "*" ] ) as cursor: for row in cursor: print row[0]
I did some quick testing here and I confirmed what Luke found: running the with statement in a function removes the locks while running it alone (outside a function) leaves the locks. However, if you run the with statement outside of a function, the locks only remain until you close the IDE (I was using PyScripter). Same thing if you just run the .py file with python.exe, the locks are removed when the script has finished running.
Lucas Danzinger addressed this behavior in one of his earlier replies to this thread, i.e., the locks are removed by the Python interpreter when the cursor objects go out of scope by either having the function end or having the IDE/interpreter closed out.