Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

    pause 10 seconds

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

share|improve this question
Interesting question. This link may prove helpful: – Aaron Sep 2 '14 at 15:42
up vote 8 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:

def funcCopyData():
    global var success = True
    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:
  lockTest = arcpy.TestSchemaLock(featureClass)


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
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 '14 at 15:39
@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 '14 at 15:44
Thanks both John and Ryan -- the TestSchemaLock function does exactly what I need. – Erica Sep 3 '14 at 11:41

Your Answer


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.