Daemonizing a python programme.

Coy Krill ckrill at qvlinc.com
Mon Mar 26 16:20:14 EST 2001


William Annis wrote:

> Coy Krill <ckrill at qvlinc.com> writes:
> >         # get our own session and fixup std[in,out,err]
> >         os.setsid()
>
>         I include these here:
>
>         os.chdir(some_sensible_root_dir_for_core_files)
>         os.umask(000)     # or whatever seems sensible
>

Thanks, I'll incorporate these ideas as well.

> >         sys.stdin.close()
> >         sys.stdout = NullDevice()
> >         sys.stderr = NullDevice()
>
>         This is curious.  Why not just close down STDOUT and STDERR,
> too?

The programmer is smart enough not to try to use any functions that read
from stdin, however, he might import a module that tries to write to
stdout or stderr which would cause the program to crash.  This allows
you to ignore any output with impunity.

Coy





More information about the Python-list mailing list