This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) |