How to release LOCK FILE?

5976
9
03-05-2014 12:01 PM
YangLiu2
New Contributor II
Hi all,

Recently, we published a GP Services. When running the GP Service on ArcMap, it works fine. However, when running it on Web Server. I got error like the screenshot: "esrijobfailed". We go to read the LOGS in ArcGIS Server Manager.
Sometimes, the error is "ExecuteError: ERROR 000871: Output table: Unable to delete the output".
Sometimes, the error is "ExecuteError: ERROR 999999: Error executing function. Cannot acquire a lock. Cannot acquire a lock. ERROR 010037: Output table D:\ArcGISData\ArcServerData\TxFIP\tools\ScratchWorkspace\scratch\scratch.gdb\tempUrbanStats could not be created".
Sometimes, it is "ERROR 999999: Error executing function. The table already exists. No spatial reference exists".
Sometimes, it is " ERROR 000464: Cannot get exclusive schema lock. Either being edited or in use by another application. Failed to execute (Delete)".

Besides, I check in the gdb folder. There are usually two lock files: _gdb.lock and tempStatsTable.lock. And they are not released after GP Services termination.
I also find that after the GP Service firstly executes, we wait several minutes and run the GP again, the GP works on Web server again though two lock files are still in gdb folder. Any thought? Thanks!

Best,
Yang
Tags (2)
0 Kudos
9 Replies
DorothyMortenson
Occasional Contributor II

Did you ever find a solution to this? I am running into something similar.

Works fine in ArcTools, create the GP Service, go to the web service and it creates a locked file.

I had thought that

del mxd (name of the mxd used)

del arcpy

would work, but it doesn't.

0 Kudos
DorothyMortenson
Occasional Contributor II

Here is the code:

def make_map(wl_id, well_label_text, well_label_nbr, well_label_lat_dd , well_label_long_dd , x_coord , y_coord, trsqq_key , address_of_well ,  submitted_by , location_source  😞
   

    # ----------- IMPORTS ----------------------------------------------------------
    import datetime, sys, arcpy, os, shutil, time  
    # ------------------------------------------------------------------------------------
     

    #===================================================================
    # PATHNAMES AND OTHER VARIABLES
    #===================================================================
    blah, blah

    #===================================================================
    # CREATE POINT
    #===================================================================
    spatialRef = arcpy.Describe(dataset).spatialReference
   
    if arcpy.Exists(temp_well_point):
        arcpy.Delete_management(temp_well_point)
        print "Old version of well point was deleted."
    
    ptx = float(x_coord)
    pty = float(y_coord)
    well_point = arcpy.Point(ptx, pty)  
    pointGeometry = arcpy.PointGeometry(well_point, spatialRef)
    logfile.write("\n... Geometry of point is created...\n")
   
    arcpy.CopyFeatures_management(pointGeometry, temp_well_point)
    arcpy.AddField_management(temp_well_point, "MAP_LABEL", "TEXT", "", "", 20)
    map_label = "\"" + well_label_nbr + "\""
    arcpy.CalculateField_management(temp_well_point, "MAP_LABEL", map_label,   "PYTHON")
   
   
    #===================================================================
    # CREATE MAP
    #===================================================================
   
    # Process: Delete pre-existing png...
    if os.path.exists(well_location_map):
        os.remove(well_location_map)

   
    # .... Change the extent to the selected area ...
    df           = arcpy.mapping.ListDataFrames(well_mxd,"Layers") [0]
    newExtent    = df.extent
    newExtent.XMin, newExtent.YMin = xmin, ymin
    newExtent.XMax, newExtent.YMax = xmax, ymax
    df.panToExtent(newExtent)
   
    #... Add the Layer and Change the Cartography .....
    wellLayer = arcpy.mapping.Layer(well_layer)
    wellLayer.replaceDataSource(workspace_temp, "SHAPEFILE_WORKSPACE", wl_id)
    arcpy.mapping.AddLayer(df, wellLayer, "TOP")
    wellLayer.showLabels = True
   
    # change the text of the map
    for elm in arcpy.mapping.ListLayoutElements(well_mxd, "TEXT_ELEMENT"):
        if elm.text == "latitude_text":
            elm.text = lat_line
        if elm.text == "longitude_text":
            elm.text = long_line 
        if elm.text == "trsqq_text":
            elm.text = trsqq_line 
        if elm.text == "well_label":
            elm.text = well_label_line                         
        if elm.text == "address_of_well_text":
            elm.text = address_of_well_line
        if elm.text == "source_text":
            elm.text = location_source
           
    # ... refresh the map .....
    arcpy.RefreshActiveView()

    arcpy.mapping.ExportToPNG(well_mxd, well_location_map)

    #===================================================================

    # CLEANUP 

    #===================================================================
    # ended up deleting the temp point to get rid of the locked files.
    # in other applications, I may not want to do this.
    #---------------------------------------------------------------------------------------------------------------------
    if arcpy.Exists(temp_well_point):
        arcpy.Delete_management(temp_well_point)

    del well_mxd
    del arcpy       
   

0 Kudos
SusanJones
Occasional Contributor II

Have you deleted all the objects that have been created in the script behind the GP Service?

ArcGIS Desktop takes care of this (mostly and usually) behind the scenes. But all objects in memory need explicit removal after use.

For example,

#create mxd in memory

mxd = arcpy.mapping.MapDocument(r'some fmxd')

#todo remove mxd

del mxd

If sounds like it is still hanging around in memory and that why it's status is lock.

Susan

0 Kudos
SusanJones
Occasional Contributor II

can you post your code in the window

0 Kudos
DorothyMortenson
Occasional Contributor II

See above.

In the cleanup section, I ended up deleting the temp point to get rid of the locked files. But in other cases, I may not want to do that.

0 Kudos
SusanJones
Occasional Contributor II

Hi Dorothy

Geoprocessing Services have changed a bit since the ArcGIS Server 10.1 release. Your code works fine at the Desktop Tool level but when applied to ArcGIS Server is does not know where to find the output result datasets it has generated.

The code will need to be modified to use the ScratchFolder, ScratchGDB and the ScratchWorkspace  arcpy variable.

ArcGIS Server goes through and validates the code when the tool is published as a service. A new task is created each time the GP Service is called and a new (temporary) sets of Scratch Workspaces are created.

Did you get any warning messages when you published the tool? It will normally tell you it couldn't figure out the path to the data because it is not know to ArcGIS Server.

http://resources.arcgis.com/en/help/main/10.1/index.html#//001w00000047000000

Susan

0 Kudos
DorothyMortenson
Occasional Contributor II

That may help me with another issue I have.

But I still don't understand why it locks the file.

0 Kudos
DorothyMortenson
Occasional Contributor II

No there were not errors, warnings or messages.

0 Kudos
SusanJones
Occasional Contributor II

I think it has locked the file because it didn't get cast as the result.

0 Kudos