Personal Geodatabase Lockfile Won't Go Away

1595
11
06-19-2012 03:15 AM
RobinPearce
New Contributor
Environment: ArcEditor/ArcMap/Arc Catalog 10.0 with Python 2.6.5

Problem: Running a script from ArcCatalog to populate an existing PGDB table from a CSV. The table gets filled perfectly but on completion of the script, the database lockfile(.ldb) doesn't disappear. Row and rows objects are both deleted in the script, so what is still holding the database? To clear the ldb, I have to close down ArcMap, then open the mdb in Access and then close it again. This defeats the whole object of convenience of staying in an ArcMap session to do a quick visual check of data just imported from CSV.

Here is my code:

import arcpy, csv

TypeOfData = str(arcpy.GetParameterAsText(0))
inputCSVfile = str(arcpy.GetParameterAsText(1))
FeatureClassTable = str(arcpy.GetParameterAsText(2))
row,rows = None,None

rows = arcpy.InsertCursor(FeatureClassTable)
fieldname = ["Last_Update","Last_Update_By","Feature_ID","Survey_ID","Survey_ID_Ref","Survey_Name","Feature_Name","Feature_Desc",
             "Symbology_Code","Symbology_Name","Line_ID","Line_Name","Easting","Northing","Depth","Altitude","Time_Stamp",
             "Heading","Remarks"]

inputTxtFile = open(inputCSVfile,"rb")
reader = csv.reader(inputTxtFile)
ID = 0

try:
  for inrow in inputTxtFile.readlines():
    if ID>0:
      itemstr = inrow.split(",")
      x = itemstr[10]
      y = itemstr[11]
      z = itemstr[12]
      m = 0
      point = arcpy.Point(x,y,z,m,ID)
      pnt = arcpy.PointGeometry(point)
      row = rows.newRow()
      row.setValue("Shape",pnt)
      row.setValue(fieldname[0],itemstr[0])
      row.setValue(fieldname[1],itemstr[1])
      if itemstr[2]!='': row.setValue(fieldname[3],itemstr[2])
      if itemstr[2]=='': row.setValue(fieldname[3],0)
      row.setValue(fieldname[4],itemstr[3])
      row.setValue(fieldname[5],itemstr[4])
      row.setValue(fieldname[6],itemstr[5])
      row.setValue(fieldname[7],itemstr[6])
      row.setValue(fieldname[8],itemstr[7])
      row.setValue(fieldname[10],itemstr[8])
      row.setValue(fieldname[11],itemstr[9])
      row.setValue(fieldname[12],itemstr[10])
      row.setValue(fieldname[13],itemstr[11])
      row.setValue(fieldname[14],itemstr[12])
      row.setValue(fieldname[15],itemstr[13])
      row.setValue(fieldname[16],itemstr[14])
      row.setValue(fieldname[17],itemstr[15])
      row.setValue(fieldname[18],itemstr[16])
      rows.insertRow(row)
      if ID%500==0: arcpy.AddMessage(ID)
    ID += 1
    if ID>100: break
  arcpy.AddMessage(ID-1)  

except:
  if not arcpy.GetMessages() == "":
    arcpy.AddMessage(arcpy.GetMessages(2))

finally:
  inputTxtFile.close()
  if row:
    del row
  if rows:
    del rows


What is really annoying, the same script runs in debug mode in PythonWin - as soon as I close PythonWin, the lockfile goes - without exiting my ArcMap session. But I don't want to use this method to run data.

What do I need to do?

Rob Pearce
Tags (2)
0 Kudos
11 Replies
MathewCoyle
Frequent Contributor
The does lock file actually stop you from doing anything? I know if FGDB lock files can persist after a session and have no impact on future sessions. I too have some lock files hanging around PGDBs after creation/processing and they don't seem impact on any analysis etc I want to do on them.
0 Kudos
JoshuaChisholm
Occasional Contributor III
I'd try (if you haven't already), removing EACH variable from memory until the lock file (hopefully) disappears. I'd start with typing "del row" and "del rows" into the console. Those lines should error since it looks like they are being properly removed in the script. Keep removing variables (like "del pnt"). "dir()" will give you the full list of all variable in memory.

Let me know if you find your culprit.
Good Luck!
0 Kudos
ChrisBater
New Contributor II
I'd try (if you haven't already), removing EACH variable from memory until the lock file (hopefully) disappears. I'd start with typing "del row" and "del rows" into the console. Those lines should error since it looks like they are being properly removed in the script. Keep removing variables (like "del pnt"). "dir()" will give you the full list of all variable in memory.

Let me know if you find your culprit.
Good Luck!



Try "del arcpy" too.
0 Kudos
KevinBell
Occasional Contributor III
del the whole pgdb and use a fgdb!:p
0 Kudos
nimitz
by
Occasional Contributor
What would be the difference between the PGDB and the FGDB?
0 Kudos
MathewCoyle
Frequent Contributor
FGDB do not have a size limit. Support multi user viewing/editing. Topology, domains etc.

As of 10.0, there really is zero reason I know of to use a PGDB unless you need to tie it to Access for some archaic reason.
0 Kudos
RobinPearce
New Contributor
To all who responded to my question - many thanks.

Regarding use of PGDB, this decision unfortunately is client-driven - perhaps later on we can move to FGDB. The limitations with Access structure are well known to our company.

The existence of the lockfile does stop us editing the PGDB in any way, most importantly via ArcMap data editing. So it's a nuisance.

Joshua C and Chris B - thanks for your suggestions - I will try that out and report back!

Rob P
Gardline Geosurvey
Gt Yarmouth
Uk
0 Kudos
RobinPearce
New Contributor
Well, I just put in a 'del' statement for every variable and object name shown with dir(). Each delete seems to work ok. This just leaves the ones beginning with underscores plus 'pywin', which presumably only gets loaded with PythonWin anyway. Saved the script, ran directly. Still resolutely locked.

I know this must be possible because running the same script from the same Catalog window in ArcMap but using PythonWin via rightclick>debug, works.  By the way, this is all on my local C drive, so no other users or network complications involved.

What is PythonWin doing to release the PGDB, that the straight script isn't?
0 Kudos
JoshuaChisholm
Occasional Contributor III
Rob, weird error. I was trying to find something wrong with your script, but it looks solid. Just one side note that shouldn't be related to this problem. Should the line "if ID>100: break" be changed to "if ID>100: continue"?

As for the lock file, does it disappear when you "del pywin"?
0 Kudos