Find the answer to your Linux question:
Results 1 to 8 of 8
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    'at' command / How to create daemon for Python script?


    So I have a python script that is consuming data from a twitter streaming API feed, and I need a way to start it running in the background, and continue running indefinitely.

    I started out trying to use cron, but considering it was more of a 'run once, and never stop' type deal, I decided to try the 'at' command instead.

    So, I downloaded at, alpine, and sendmail, and the at command works as advertised when doing simple things such as echoing some string.

    I have also noticed, that when I run the python script using the at command, I can kill the python process manually, and I will see the python stack trace in my inbox, all as expected.

    However, when I start the at command, and then log out of the machine, the script will run for a good few hours, but then it will die, without mailing anything to my inbox.

    Mind you, I am running all of this as root.

    Is there some explanation for why I am not receiving the python stack trace in my mail box when the script dies (for whatever reason it's dying)?

    Otherwise, can someone suggest a better way to make this python script into a daemon/service?

    Thanks guys.

  2. #2
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    2,103
    'at' is a simple scheduler. Running a server involve daemonizing it. You can either do that in Python and execute a startup script or you can use something like the daemonize utility found here: daemonize

    Here's a good example of a Python daemon: A simple unix/linux daemon in Python - Lone Wolves - Web, game, and open source development

  3. #3
    Quote Originally Posted by gregm View Post
    'at' is a simple scheduler. Running a server involve daemonizing it. You can either do that in Python and execute a startup script or you can use something like the daemonize utility found here: ...

    Here's a good example of a Python daemon:...]
    Thank you gregm! The daemonize tool looks perfect, and even pays homage to Stevens, I think I'll give that a try first.

    P.S. Wow the python script pays homage as well - see Stevens' "Advanced Programming in the UNIX Environment" for details

    I have both of these books sitting on my shelf as I'm trying to get through the GOF so I can read them. Which one should I approach first I wonder?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    2,103
    Personally I have found all of Stevens books far more valuable then GOF. Patterns are best approached with a good understanding of programming first and a then with a healthy dose of common sense thrown in.

  6. #5
    Yeah I would assume that. I have been programming in Java for awhile, and while some of the patterns introduced in GOF are concepts which we all pick up on eventually, some I would probably not have found on my own for awhile. Besides, it helps to put a name to a concept.

    But GOF does seem to be a bit more of a reference book than study material. I will probably enjoy Stevens books quite a bit more, but right now I am also trying to get through tldp tutorials first, so I have some background for when I start reading.

  7. #6
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    2,103
    Both APUE and UNP give you the basics of UNIX programming. Advanced Programming in the Linux Environment is an excellent book that follows the structure of APUE. Time does march on but the Stevens books give a good solid basis for UNIX system programmers in C or any language modeled on it.

  8. #7
    Are you saying that prerequisites aren't rally required to begin reading either book? Or that there isn't any particular order they should be read in?

    Since APUE has "Advanced" in it's title, I assumed I should know all the basics before attempting to approach it. Hmm. I guess I'll flip through both of these when I get home to get a better idea of what the content is like. Also, I haven't heard of APLE before, what does it offer that APUE doesn't? I'm assuming it's basically the same content, geared more towards the Linux environment?

  9. #8
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    2,103
    APLE is Linux specific and it is more up to date. APUE still is applicable but somewhat dated, as is UNP. If you intend to program for Linux APLE gives better coverage.

    The Advanced portion really means that it won't teach you to be a C programmer. It's a UNIX programming tutorial not a C tutorial.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •