I have a Python app running on Linux. It is called every minute from cron. It checks a directory for files and if it finds one it processes it - this can take several minute
I think fcntl.lockf is what you are looking for.