daemonize.py
Create daemon process.
This library is considered production ready.
foo.py
:
# foo.py
import time
from pykit import daemonize
def run():
for i in range(100):
print i
time.sleep(1)
if __name__ == '__main__':
# there is at most only one of several processes with the same pid path
# that can run.
daemonize.daemonize_cli(run, '/var/run/pid')
To control foo.py from command line:
python2 foo.py start
python2 foo.py stop
python2 foo.py restart
Help to create daemon process. It supplies a command line interface API to start/stop/restart a daemon.
daemonize
identifies a daemon by the pid
file.
Thus two processes those are set up with the same pid
file
can not run at the same time.
syntax:
daemonize.daemonize_cli(callable, pid_path, close_fds=False)
Read command line arguments and then start, stop or restart a daemon process.
arguments:
-
callable
: a callable object such as afunction
orlambda
to run after the daemon process is created. -
pid_path
: abosolute path ofpid
file. It is used to identify a daemon process. Thus two processes those are with the samepid
file can not run at the same time. -
close_fds
: If it isTrue
, besidesstdin
,stdout
andstderr
, all other file descriptors will also be closed.
return: None
Zhang Yanpo (张炎泼) [email protected]
The MIT License (MIT)
Copyright (c) 2015 Zhang Yanpo (张炎泼) [email protected]