Test if Script Already Running

Matt matt.mailinglists at gmail.com
Tue Apr 18 20:31:17 EDT 2017

I have a number of simple scripts I run with cron hourly on Centos
linux.  I want the script to check first thing if its already running
and if so exit.

In perl I did it with this at the start of every script:

    use Fcntl ':flock';
    INIT {
        open LH, $0 or die "Can't open $0 for locking!\nError: $!\n";
        flock LH, LOCK_EX | LOCK_NB or die "$0 is already running somewhere!\n";

How can I do something like this in Python?

More information about the Python-list mailing list