Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

My script needs to copy data into a feature class to an SDE geodatabase that might have a lock on it from another application. I shouldn't break the lock (that app has priority over a data update), but I also don't want the script to quit just because it tried at the wrong moment.

How can I set it to keep trying until there is no lock? I'm looking for something like a try/except, but more like try/keep-trying-every-15-seconds.

I considered making a separate function and adding a pause:

try:
    funcCopyData()
except:
    pause 10 seconds
    funcCopyData()

but wouldn't this still be limit me to only two attempts?

share|improve this question
1  
Interesting question. This link may prove helpful: stackoverflow.com/q/2785821/1446289 –  Aaron Sep 2 at 15:42

1 Answer 1

up vote 7 down vote accepted

Ok, let me start this with I am no python expert, so there are probably much more efficient ways to accomplish this, but... the first thought that comes to me would be maybe something along the lines of the following (pseudo code below)

while success != True:
  funcCopyData()

def funcCopyData():
  try
    ...
    ...
    global var success = True
  except
    pause 10 sec

I don't know if that would work correctly or not as I don't know if the except would escape the while loop... but hopefully that at least gives you a thought.

Or you might look at the TestSchemaLock function and try something along the lines of

import arcpy, time
lockTest = arcpy.TestSchemaLock(featureClass)

while lockTest != True:
  time.sleep(10)
  lockTest = arcpy.TestSchemaLock(featureClass)

funcCopyData()

def funcCopyData():
  ...
  ...

I've never used the TestSchemaLock though, so I make no guarantees, but it sounds like it might meet what you are needing.

Hope it helps, edits/corrections welcome.

share|improve this answer
1  
I was just in the middle of posting practically the same code as you with "TestSchemaLock". I've also updated your second example code with the "time.sleep" function for pausing. –  RyanDalton Sep 2 at 15:39
1  
@RyanDalton, sorry about that, I'd have let you post it had I know. But thank you for correcting the code, too many function's I've heard of but not actually used before. –  John Sep 2 at 15:44
    
Thanks both John and Ryan -- the TestSchemaLock function does exactly what I need. –  Erica Sep 3 at 11:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.