Select to view content in your preferred language

repeated AddField operations fails in 10.1, works in 10.0

5459
20
Jump to solution
09-10-2012 06:00 PM
TomTyndall
Deactivated User
The following code is throwing exceptions. The exception occurs at different places in the code; where it breaks on one run it may have successfully gotten past on a previous run.

Here's the error I'm receiving:
ExecuteError: ERROR 000464: Cannot get exclusive schema lock.  Either being edited or in use by another application.
Failed to execute (AddField).

This code runs without issue under 10.0.

import arcpy import os, sys from xml.etree import cElementTree as ElementTree  def addCoreFields(fc):     arcpy.AddField_management(fc, "AssetObjectId", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")     arcpy.AddField_management(fc, "AssetId", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")     arcpy.AddField_management(fc, "AssetObjectStatus", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")     arcpy.AddField_management(fc, "Status", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")     arcpy.AddField_management(fc, "Feature", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")     arcpy.AddField_management(fc, "SubFeature", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")     arcpy.AddField_management(fc, "AssetCode", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")     arcpy.AddField_management(fc, "LaneLocation", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")     arcpy.AddField_management(fc, "Route", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")     arcpy.AddField_management(fc, "FromMilepost", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")     arcpy.AddField_management(fc, "FromOffset", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")     arcpy.AddField_management(fc, "ToMilepost", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")     arcpy.AddField_management(fc, "ToOffset", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")         if __name__ == '__main__':     scriptPath = sys.path[0]     dataGDB = os.path.join(scriptPath, "data.gdb")     if arcpy.Exists(dataGDB): arcpy.Delete_management(dataGDB)     arcpy.CreateFileGDB_management(scriptPath, "data")      sr = "PROJCS['NAD_1983_StatePlane_Arizona_Central_FIPS_0202_Feet_Intl',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',700000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-111.9166666666667],PARAMETER['Scale_Factor',0.9999],PARAMETER['Latitude_Of_Origin',31.0],UNIT['Foot',0.3048]];-17746700 -44067300 3048;-100000 10000;-100000 10000;3.28083989501312E-03;0.001;0.001;IsHighPrecision"     for name in ['one', 'two', 'three']:           fc = os.path.join(dataGDB, name)         arcpy.CreateFeatureclass_management(dataGDB, name, "POINT", "", "DISABLED", "DISABLED", sr, "", "0", "0", "0")         addCoreFields(fc)
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor
with that extra second of execution time per added per field my geo proc just got a lot slower.


I suggest creating a template table or feature class in the in_memory workspace -- the Add Fields happen very fast with no file-locking issues -- and then you can use the in_memory dataset as a template for CreateTable or CreateFeatureClass to disk.

View solution in original post

0 Kudos
20 Replies
MathewCoyle
Honored Contributor
Is it always the addfield function that breaks it or do other tools throw the same exception?

In 10.0 I had a similar issue iirc with AddField. For some reason putting the parameters in a list and referencing those solved the issue. I may be misremembering though, it was several months ago now. I did read a post on here about 10.1 not releasing locks as fast as previously. Adding a Compact or Exists was the work around for it.


Here's my code if you are interested.
def addfields():
    print "Adding fields"
    field_name_list = [field.name for field in arcpy.ListFields(calc_table)]
    add_fields = [
        ("TYPE", "TEXT", "#", "#", 40),
        ("ORIGIN_SITE", "TEXT", "#", "#", 10),
        ("UTYPE", "TEXT", "#", "#", 40),
        ("U_ORIGIN_SITE", "TEXT", "#", "#", 10),
        ("DEC_PER", "SHORT", "#", "#", "#"),
        ("LEAD_CON", "TEXT", "#", "#", 2),
        ("COV_GRP", "TEXT", "#", "#", 2),
        ("STRATA", "SHORT", "#", "#", "#"),
        ("CON_PIECE", "FLOAT", "#", "#", "#"),
        ("DEC_PIECE", "FLOAT", "#", "#", "#"),
        ("CON_VOLHA", "FLOAT", "#", "#", "#"),
        ("DEC_VOLHA", "FLOAT", "#", "#", "#"),
        ("UDEC_PER", "SHORT", "#", "#", "#"),
        ("UCOV_GRP", "TEXT", "#", "#", 2),
        ("ULEAD_CON", "TEXT", "#", "#", 2),
        ("TDASTRATUM", "TEXT", "#", "#", 8),
        ("UTDASTRATUM", "TEXT", "#", "#", 8)]
    for field in add_fields:
        if field[0] not in field_name_list:
            arcpy.AddField_management(
                calc_table,
                field[0],
                field[1],
                field[2],
                field[3],
                field[4])
0 Kudos
ChrisSnyder
Honored Contributor
I also had occasional issues with repetitive calls to AddField dropping the error:

ERROR 000464: Cannot get exclusive schema lock. Either being edited or in use by another application.

What I was able to ultimately deduce is that it was my virus scan software, which I assume, was identifying repetitive calls to AddField as "suspicious". As I recall, all of a sudden right after a McAfee upgrade, all my scripts started sporadically failing... All of them where the AddField was running in a loop. Upon disabling McAfee, the problem was solved.

Possible solution: Try disabling/fiddling your virus scan software, or move to another virus scan software.
0 Kudos
TomTyndall
Deactivated User
Yes, its always the AddField tool that causes the problem. Your comment about not releasing locks fast enough is a dead on description of the behavior I'm seeing. I just tried inserting an arcpy.exist call between each addfield call to try and slow things down a bit but still the same problem. So to really force the issue, I inserted a python time.sleep call between each addfield trying first a tenth of second - same problem, a full second and fixed!

Before your response, I put all those core fields in a template fc and use that for the initial schema definition. But I still have unique fields that get added to the created fc's and now with that extra second of execution time per added per field my geo proc just got a lot slower.

Thanks for the help,
Tom Tyndall
Sr. GIS Programmer
Arizona Dept. of Transportation
0 Kudos
curtvprice
MVP Esteemed Contributor
with that extra second of execution time per added per field my geo proc just got a lot slower.


I suggest creating a template table or feature class in the in_memory workspace -- the Add Fields happen very fast with no file-locking issues -- and then you can use the in_memory dataset as a template for CreateTable or CreateFeatureClass to disk.
0 Kudos
ChrisSnyder
Honored Contributor
in_memory workspace -- the Add Fields happen very fast with no file-locking issues


..DeleteField runs like a champ in_memory too.
0 Kudos
TomTyndall
Deactivated User
Curtis's suggestion about building and adding fields to an in memory feature class did the trick.

Here's the final code. Thanks everyone.
TT

import arcpy
import os, sys
    
def addCoreFields(fc):
    arcpy.AddField_management(fc, "AssetObjectId", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.AddField_management(fc, "AssetId", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.AddField_management(fc, "AssetObjectStatus", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.AddField_management(fc, "Status", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.AddField_management(fc, "Feature", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.AddField_management(fc, "SubFeature", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.AddField_management(fc, "AssetCode", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.AddField_management(fc, "LaneLocation", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.AddField_management(fc, "Route", "TEXT", "", "", "32", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.AddField_management(fc, "FromMilepost", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.AddField_management(fc, "FromOffset", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.AddField_management(fc, "ToMilepost", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.AddField_management(fc, "ToOffset", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
       
if __name__ == '__main__':
    scriptPath = sys.path[0]
    dataGDB = os.path.join(scriptPath, "data.gdb")
    if arcpy.Exists(dataGDB): arcpy.Delete_management(dataGDB)
    arcpy.CreateFileGDB_management(scriptPath, "data")

    for name in ['one', 'two', 'three']:  
        fc = arcpy.CreateFeatureclass_management("in_memory", name, "POINT", "", "DISABLED", "DISABLED", "", "", "0", "0", "0")
        addCoreFields(fc)
        arcpy.CopyFeatures_management(fc, os.path.join(dataGDB, name))
        arcpy.Delete_management(fc)
0 Kudos
ChrisSnyder
Honored Contributor
Note that virus scan software leaves the in_memory workspace alone (since it's not on disk)...
0 Kudos
TomTyndall
Deactivated User
I'd like to investigate the role that antivirus software has on this but I have no control over that environment, either on my workstation or on the ArcGIS Server machine, where this script is ultimately headed. Given the new problems I'm having regarding in_memory datasets I'm wondering if anyone has any further ideas on this problem?
0 Kudos
ChrisSnyder
Honored Contributor
Work around idea: Manually build the FC schema how you want it, and store it somewhere.... And then reference that "template" FC in the arcpy.CreateFeatureclass_management() tool, thus negating the need to run the AddField() tool.

Question: What virus scan software are you running on your workstation? I noticed this issue with Symantec, upon switching McAfee it went away.
0 Kudos