Getting models to check for or wait for lock files to clear

3026
4
10-11-2015 09:49 PM
LindsayRaabe
New Contributor III

Is there a way in model builder to set the model to look for lock files on all data used in the process before commencing? Alternatively, is there a way to get the model to wait for a lock file to clear before continuing instead of just stopping and leaving everything half done?

Whilst these are the preferable methods, if they can't be achieved, can it be set up to skip steps and go down an alternative path which I could write to restore the original data (my model makes copies of the old data before commencing, which get deleted at the end if it completes all processes successfully in case another user access the data and interrupts the processes).

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

Are you looking to test prior to a using a particular tool? or just in general?

Rules for working with schema locks—Help | ArcGIS for Desktop

TestSchemaLock—Help | ArcGIS for Desktop

LindsayRaabe
New Contributor III

Either way. Just trying to figure out a better way to do it than waiting and seeing if it succeeds which is what happens currently when someone interrupts from elsewhere in the network. It would be good to have it built in as as part of the model so that it's all wrapped up in a simple operation though.

0 Kudos
DanPatterson_Retired
MVP Emeritus

There must be an environment setting that you can use in modelbuilder that allows for the check.  When it comes to network locks...I presume that it would be the same but it would cripple a model and you would have to bail since you have no clue when the lock would be released if ever.  ​

0 Kudos
FreddieGibson
Occasional Contributor III

There is a function in arcpy to allow you to test for schema locks.

TestSchemaLock

http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-functions/testschemalock.htm

You will want to implement If-then-Logic in your model if you want it to continue working if it is unable to get an exclusive lock. An example of this is shown on the following page:

Using If-Then-Else logic for branching

http://desktop.arcgis.com/en/desktop/latest/analyze/modelbuilder/using-if-then-else-logic-for-branch...

You would need to essentially modify the code uses within the examples to leverage the TestSchemaLock method. This would allow you to skip portions of your model if they aren't ready to run. As a more advanced idea, you may be able to implement logic in the script that could check for the locks over a period of time prior to updating the model if it can continue.

Python time.sleep method

http://www.tutorialspoint.com/python/time_sleep.htm