Created
October 24, 2011 17:57
-
-
Save carlopires/1309650 to your computer and use it in GitHub Desktop.
Easy python daemon
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
# -*- coding: utf-8 -*- | |
""" | |
Created on 23/10/2011 | |
@author: Carlo Pires <[email protected]> | |
""" | |
import sys | |
import time | |
from daemon import DaemonContext | |
from daemon.runner import make_pidlockfile, is_pidfile_stale | |
pidfile = make_pidlockfile('/tmp/daemon.pid', 0) | |
if is_pidfile_stale(pidfile): | |
pidfile.break_lock() | |
if pidfile.is_locked(): | |
print 'daemon is running with PID %s already' % pidfile.read_pid() | |
sys.exit(0) | |
with DaemonContext(pidfile=pidfile): | |
for i in range(1,30): | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment