I have a python Django manage command that should be called upon receiving an input file but this command is not safe for parallel calls. So an input file should be processed only and only when there is no other file being processed.
One solution that I have is to use a lock file. Basically, create a lock file at the start of the process and delete it at the end.
I'm worried that if the process crashes the lock file won't be deleted and consequently none of the other files would be processed until we manually remove that lock file.
The solution doesn't need to be specific for Django or even python, but what is the best practice to enforce that only one instance of this process is being run?