write to closed console fails on FreeBSD but not Linux?

Doug McNaught doug at mcnaught.org
Fri Oct 26 12:14:34 EDT 2001


usenet at jeffjohnson.net (Jeff Johnson) writes:

> I'm running a Python program as a daemon on FreeBSD 4.3 and Python
> 2.1.1.  It was crashing just after I would close the console because
> printing to sys.stdout after the console was closed produced IO
> errors.  I found a few solutions from other usenet posts, I chose to
> set sys.stdout and sys.stderr to a file-like class that doesn't write
> to anything.

FWIW, the canonical way to run as a daemon under Unix is: 

1) Close stdin, stdout, stderr and reopen them to '/dev/null' (or
   logfiles if you like). 
2) fork()
3) call setsid() in the child, parent exits, child does the work.

-Doug



More information about the Python-list mailing list