I have created a Python package and released it on PyPI, say spamandeggs
. This package is cross-platform (Windows,GNU/Linux, MacOSX) aimed at updating the user with certain information periodically (say every 5 minutes). The package can be run from command-line through the command spamtheeggs
.
Here are the issues I am facing:
Question 01 : How to daemonize the script running through the spamtheeggs
command?
Problem : Following this answer, I tried using schedule
in my script. This works fine for scheduling but the execution is not daemonized. The terminal is busy for the entirety of the process.
I would like to know a way to daemonise the Python package.
Question 02 : How to add the command as a cron job for scheduled execution ?
Solution 01 : One way to do this would be to write an installation guide describing the process (editing crontab using crontab -e
, etc.). Drawback : Not appealing.
Solution 02 : As the author of the package, I want to be able to add this command to the user's crontab (after getting user's confirmation, obviously).
Options:
I would like to know which option is suitable(if any) and any tips on how can I go about working on them.
List of resources I have read so far:
Note: I would appreciate if the solution is applicable over all the 3 platforms.
PS: This is my first attempt at cron and daemon jobs.
python-deamon
package can help you, it works in 2 modes:
using a runner (I think is just what you want): http://www.gavinj.net/2012/06/building-python-daemon-process.html
or running using daemon.DaemonContext
directly (a more traditional way)
python-deamon
has no documentation, but I've found some code that may help you http://www.programcreek.com/python/example/10392/daemon.DaemonContext
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.