python pid file
Install lockfile:
Choose your path, remember is has to be writable by the user who invokes your python program. Here's an example:
As long as the process is running there will be a file named
https://github.com/openstack/pylockfile
$ pip install lockfile
Choose your path, remember is has to be writable by the user who invokes your python program. Here's an example:
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 sys | |
from time import sleep | |
from lockfile.pidlockfile import PIDLockFile | |
if __name__ == '__main__': | |
# If we can't acquire a lock in 1 second, raise an exception. | |
with PIDLockFile('/home/me/script.pid', timeout=1): | |
while True: | |
sys.stdout.write('Check /home/me/script.pid for my process id\n') | |
sleep(1) |
/home/me/script.pid
containing the process id; this PID file can be used as a lock file to prevent multiple processes from running at the same time, in case that wasn't already obvious :)https://github.com/openstack/pylockfile
0 Comments:
Post a Comment
<< Home