Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>  In <[EMAIL PROTECTED]>, Vincent Delporte wrote:
> 
> > Anyone knows if those lines are necessary, why, and what their
> > alternative is in Python?
> > 
> > open STDOUT, '>/dev/null'; 
> 
>  sys.stdout = open(os.devnull, 'w') 

This doesn't have the desired effect

If you run this

  import os,sys,time
  print os.getpid()
  sys.stdout = open(os.devnull, 'w')
  time.sleep(60)

It prints its pid.

$ ls -l /proc/32004/fd
total 4
lrwx------ 1 ncw ncw 64 Nov 28 09:55 0 -> /dev/pts/17
lrwx------ 1 ncw ncw 64 Nov 28 09:55 1 -> /dev/pts/17
lrwx------ 1 ncw ncw 64 Nov 28 09:55 2 -> /dev/pts/17
l-wx------ 1 ncw ncw 64 Nov 28 09:55 3 -> /dev/null

That quite clearly shows that stdout isn't /dev/null which is required
for proper deamonisation under unix.

I'm not sure how you do open stdout to /dev/null in python though!

I suspect something like this...

  import posix
  posix.close(1)
  posix.open("/dev/null", posix.O_WRONLY)


-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to