Skip to content

Instantly share code, notes, and snippets.

View abhinaythurlapati's full-sized avatar

abhinaythurlapati

View GitHub Profile
@brainsik
brainsik / gist:4280136
Created December 13, 2012 21:31
A simple way for Python cron tasks to exit if another process is currently running. Does not use a pidfile.
import os
import subprocess
import shlex
def bail_if_another_is_running():
cmd = shlex.split("pgrep -u {} -f {}".format(os.getuid(), __file__))
pids = subprocess.check_output(cmd).strip().split('\n')
if len(pids) > 1:
pids.remove("{}".format(os.getpid()))