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?


1 Answer 1


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.

  • 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. Commented Sep 2, 2014 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
    Commented Sep 2, 2014 at 15:44
  • Thanks both John and Ryan -- the TestSchemaLock function does exactly what I need.
    – Erica
    Commented Sep 3, 2014 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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