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:
- Write a Python script to schedule another script (Is this even possible?)
- Use a task scheduler which can also daemonize.
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:
- How to run a python background process periodically
- Scheduling Python Script to run every hour accurately
- How to package a Python daemon with setuptools
- Execute python Script on Crontab
- running a python script with cron
- Creating a Cron Job - Linux / Python
- How to make Python script run as service?
Note: I would appreciate if the solution is applicable over all the 3 platforms.
P.S: This is my first attempt at cron and daemon jobs.