redirecting sdtout/sdterr in a daemon

Dave Kuhlman dkuhlman at
Tue Oct 30 17:50:55 CET 2001

Possibly your output is being buffered and is not being flushed.

If that's the problem, then consider using something like the

# ====================
class Output:
    def __init__(self, infilename):
        self.infilename = infilename
    def write(self, msg):
        f = open(self.infilename, 'a')

sys.stdout = Output('mylog.log')
# ====================

You can also use 'flush' instead of opening and closing for each

You can even do sys.stdout.flush().

By the way, is outputhandle in you code really a string and the
name of the output file?  It should be.

  - Dave

Rajarshi Guha <rxg218 at> wrote:
> Hi,
>   I'm using the module to make my code run as a daemon. 
> However the module contains the lines:
> sys.stdout = NullDevice()
> sys.stderr = NullDevice()
> Instead of this behaviour I would like it to write output to a file. So I 
> write:
> sys.stderr = open(outputhandle,'w')
> sys.stdout = open(outputhandle,'w')
> Where outputhandl is a passed to the function. However no output comes to 
> the this file. In addition when i try and print anything from the function, 
> nothing is output.


Dave Kuhlman
dkuhlman at

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

More information about the Python-list mailing list