6

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?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Sep 2, 2014 at 15:09
1

1 Answer 1

9

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.

Erica
8,9824 gold badges35 silver badges85 bronze badges
answered Sep 2, 2014 at 15:23
3
  • 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. Commented Sep 2, 2014 at 15:44
  • Thanks both John and Ryan -- the TestSchemaLock function does exactly what I need. Commented Sep 3, 2014 at 11:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.