9018be18f9 | ||
---|---|---|
docs | ||
tests | ||
.gitignore | ||
.travis.yml | ||
LICENSE | ||
MANIFEST.in | ||
Makefile | ||
README.rst | ||
daemonize.py | ||
setup.cfg | ||
setup.py |
README.rst
daemonize
daemonize is a library for writing system daemons in Python. It is distributed under MIT license. Latest version can be downloaded from PyPI. Full documentation can be found at ReadTheDocs.
Dependencies
It is tested under following Python versions:
- 2.6
- 2.7
- 3.3
- 3.4
- 3.5
Installation
You can install it from Python Package Index (PyPI):
$ pip install daemonize
Usage
from time import sleep
from daemonize import Daemonize
= "/tmp/test.pid"
pid
def main():
while True:
5)
sleep(
= Daemonize(app="test_app", pid=pid, action=main)
daemon daemon.start()
File descriptors
Daemonize object's constructor understands the optional argument keep_fds which contains a list of FDs which should not be closed. For example:
import logging
from daemonize import Daemonize
= "/tmp/test.pid"
pid = logging.getLogger(__name__)
logger
logger.setLevel(logging.DEBUG)= False
logger.propagate = logging.FileHandler("/tmp/test.log", "w")
fh
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)= [fh.stream.fileno()]
keep_fds
def main():
"Test")
logger.debug(
= Daemonize(app="test_app", pid=pid, action=main, keep_fds=keep_fds)
daemon daemon.start()