Python shell scripting and errors

Discussion in 'Python' started by Phillip B Oldham, Feb 23, 2009.

  1. I've got a python script running as a daemon (using someone else's
    daemon module). It runs fine for a while, but will occasionally balk
    and die. Since its running in the background, I'm getting no error
    from it.

    What's the best way to capture the output into a file for later review?
    Phillip B Oldham, Feb 23, 2009
    #1
    1. Advertising

  2. Phillip B Oldham

    Tim Wintle Guest

    On Mon, 2009-02-23 at 09:12 -0800, Phillip B Oldham wrote:
    > I've got a python script running as a daemon (using someone else's
    > daemon module). It runs fine for a while, but will occasionally balk
    > and die. Since its running in the background, I'm getting no error
    > from it.
    >
    > What's the best way to capture the output into a file for later review?


    Point standard out to an open file handle?
    Tim Wintle, Feb 23, 2009
    #2
    1. Advertising

  3. On Feb 23, 2009, at 12:21 PM, Tim Wintle wrote:

    > On Mon, 2009-02-23 at 09:12 -0800, Phillip B Oldham wrote:
    >> I've got a python script running as a daemon (using someone else's
    >> daemon module). It runs fine for a while, but will occasionally balk
    >> and die. Since its running in the background, I'm getting no error
    >> from it.
    >>
    >> What's the best way to capture the output into a file for later
    >> review?

    >
    > Point standard out to an open file handle?


    And stderr.

    I don't know how the OP's daemon is being launched, but the crontab
    command below worked for me for redirecting errors to a log file
    without the need to modify the script.

    python /usr/local/foo/bar.py >> /var/log/foo/bar.txt 2>&1



    HTH
    Philip
    Philip Semanchuk, Feb 23, 2009
    #3
  4. Phillip B Oldham

    birdsong Guest

    On Feb 23, 9:34 am, Philip Semanchuk <> wrote:
    > On Feb 23, 2009, at 12:21 PM, Tim Wintle wrote:
    >
    > > On Mon, 2009-02-23 at 09:12 -0800, Phillip B Oldham wrote:
    > >> I've got a python script running as a daemon (using someone else's
    > >> daemon module). It runs fine for a while, but will occasionally balk
    > >> and die. Since its running in the background, I'm getting no error
    > >> from it.

    >
    > >> What's the best way to capture the output into a file for later  
    > >> review?

    >
    > > Point standard out to an open file handle?

    >
    > And stderr.
    >
    > I don't know how the OP's daemon is being launched, but the crontab  
    > command below worked for me for redirecting errors to a log file  
    > without the need to modify the script.
    >
    > python /usr/local/foo/bar.py >> /var/log/foo/bar.txt 2>&1


    If the daemon module is worth it's salt, it will have probably closed
    all open filehandles including STDOUT and STDERR. So this might not
    work.

    If all you want is some temporary debugging, add some redirection for
    stdout and stderr after you daemonize.

    import sys
    sys.stderr = open('/path/to/suitable_stderr_file', 'w')
    sys.stdout = open('/path/to/suitable_stdout_file', 'w')


    I'm pretty sure this should catch any tracebacks.

    >
    > HTH
    > Philip
    birdsong, Feb 23, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    920
    Mark Goldin
    Jan 17, 2004
  2. Ron Stephens
    Replies:
    23
    Views:
    2,787
    Ron Stephens
    Apr 12, 2004
  3. A.M
    Replies:
    11
    Views:
    674
  4. Christian Heimes
    Replies:
    0
    Views:
    583
    Christian Heimes
    Feb 27, 2008
  5. Michael Torrie
    Replies:
    1
    Views:
    264
    alex23
    Apr 24, 2008
Loading...

Share This Page