3

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:

  1. Write a Python script to schedule another script (Is this even possible?)
  2. 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:

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.

Community
  • 1
  • 1
Kshitij Saraogi
  • 6,821
  • 8
  • 41
  • 71
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. Also see [Where do I post questions about Dev Ops?](http://meta.stackexchange.com/q/134306) – jww Jan 26 '17 at 08:03
  • @jww Thanks for notifying me about this. I considered posting this question here because it satisfied the last two points of the SO guidelines: `software tools commonly used by programmers; and is a practical, answerable problem that is unique to software development`. But if you do not think likewise, feel free to move it to a more suitable site. – Kshitij Saraogi Jan 26 '17 at 08:17

1 Answers1

1

python-deamon package can help you, it works in 2 modes:

python-deamon has no documentation, but I've found some code that may help you http://www.programcreek.com/python/example/10392/daemon.DaemonContext

cbuchart
  • 10,847
  • 9
  • 53
  • 93
  • This kind of links may become broken over the time, it would be better if, in addition, you could summarise them and improve your post with an example. – cbuchart May 10 '17 at 18:36