closing stdin, stdout and stderr

Martijn Brouwer e.a.m.brouwer at alumnus.utwente.nl
Mon Dec 26 19:16:07 EST 2005


On Mon, 2005-12-26 at 23:15 +0000, Robin Becker wrote:
> Robin Becker wrote:
> > Martijn Brouwer wrote:
> > 
> >> I am writing a unix daemon in python, so I want to close stdin, stdout
> >> and stderr.
> >> My first attempt was to the standard file descriptors using their
> >> close() methods. After closing stdout, I could not print anymore, so
> >> this seemed to work. However, later I noticed that they were not really
> >> closed. When I close them using os.close(), it did work.
> >> What is the difference between these two methods and what is the reason
> >> behind it? It took me a day to find out why I could not log out after
> >> starting the daemon.
> >>
> >> Martijn
> >>
> >>
> >>
> > I've had excellent results with variants of the cookbook entry at
> > 
> > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731
> > 
> but perhaps you're using a non unix OS, which will make that recipe wrong.

Well, I am writing a unix daemon ;)

Martijn





More information about the Python-list mailing list