redirecting sdtout/sdterr in a daemon

Dave Kuhlman dkuhlman at rexx.com
Tue Oct 30 11:50:55 EST 2001


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

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

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

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


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

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 psu.edu> wrote:
> 
> Hi,
>   I'm using the daemonize.py 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.

[snip]

-- 
Dave Kuhlman
dkuhlman at rexx.com


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



More information about the Python-list mailing list