Python daemonizer for Unix, Linux and OS X
Project description
Python daemonizer class
====================
This is a Python class that will daemonize your Python script so it can continue running in the background. It works on Unix, Linux and OS X, creates a PID file and has standard commands (start, stop, restart) + a foreground mode.
Based on [this original version from jejik.com](http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/).
Usage
---------------------
Define a class which inherits from `Daemon` and has a `run()` method (which is what will be called once the daemonization is completed.
from daemon import Daemon
class pantalaimon(Daemon):
def run(self):
# Do stuff
Create a new object of your class, specifying where you want your PID file to exist:
pineMarten = pantalaimon('/path/to/pid.pid')
pineMarten.start()
Actions
---------------------
* `start()` - starts the daemon (creates PID and daemonizes).
* `stop()` - stops the daemon (stops the child process and removes the PID).
* `restart()` - does `stop()` then `start()`.
Foreground
---------------------
This is useful for debugging because you can start the code without making it a daemon. The running script then depends on the open shell like any normal Python script.
To do this, just call the `run()` method directly.
pineMarten.run()
Continuous execution
---------------------
The `run()` method will be executed just once so if you want the daemon to be doing stuff continuously you may wish to use the [sched][1] module to execute code repeatedly ([example][2]).
[1]: http://docs.python.org/library/sched.html
[2]: https://github.com/serverdensity/sd-agent/blob/master/agent.py#L339
====================
This is a Python class that will daemonize your Python script so it can continue running in the background. It works on Unix, Linux and OS X, creates a PID file and has standard commands (start, stop, restart) + a foreground mode.
Based on [this original version from jejik.com](http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/).
Usage
---------------------
Define a class which inherits from `Daemon` and has a `run()` method (which is what will be called once the daemonization is completed.
from daemon import Daemon
class pantalaimon(Daemon):
def run(self):
# Do stuff
Create a new object of your class, specifying where you want your PID file to exist:
pineMarten = pantalaimon('/path/to/pid.pid')
pineMarten.start()
Actions
---------------------
* `start()` - starts the daemon (creates PID and daemonizes).
* `stop()` - stops the daemon (stops the child process and removes the PID).
* `restart()` - does `stop()` then `start()`.
Foreground
---------------------
This is useful for debugging because you can start the code without making it a daemon. The running script then depends on the open shell like any normal Python script.
To do this, just call the `run()` method directly.
pineMarten.run()
Continuous execution
---------------------
The `run()` method will be executed just once so if you want the daemon to be doing stuff continuously you may wish to use the [sched][1] module to execute code repeatedly ([example][2]).
[1]: http://docs.python.org/library/sched.html
[2]: https://github.com/serverdensity/sd-agent/blob/master/agent.py#L339
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
py_daemon-0.1.2.tar.gz
(4.3 kB
view details)
Built Distribution
py_daemon-0.1.2-py2.7.egg
(7.7 kB
view details)
File details
Details for the file py_daemon-0.1.2.tar.gz
.
File metadata
- Download URL: py_daemon-0.1.2.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dc5aa09650c11be42931e7fec4dda96245ece214233d259743fba153a87f287 |
|
MD5 | c22c0f1f778d75b0712e7ad655e9165e |
|
BLAKE2b-256 | 974414be0149111e8b5c520d9597fcaca9036d3e5cb646132eacb655e4b5344a |
File details
Details for the file py_daemon-0.1.2-py2.7.egg
.
File metadata
- Download URL: py_daemon-0.1.2-py2.7.egg
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ec590ab420c56223c41099883be8ba27576b5bd7b07a9effeb717263e5e49f0 |
|
MD5 | b8ff3193facdf4be4a89a61412f41b9d |
|
BLAKE2b-256 | 51d706be1f53d3e3363fe75279b15d3d8a7972e1622d9b2f55000a8e3d6b83df |