I have two Python scripts, that both need at regular intervals (think cronjobs) to call an external program.
If this program (over which we have no control) is called twice simultaneously, data errors occur, so we need to have a way to synchronize calls to this binary.
Is there a way to do this, preferably using only the Python standard library?
So without using a 3rd-party library such as filelock you'll have to do something like this:
The better approach is to use filelock (if you can install 3rd party libraries):
You can easily install filelock using pip:
See also related: Locking a file in Python
Note: There also seems to be a very similarly named package called lockfile! (Don't confuse the two!)