#NEWLINE# def daemonize( self ) : #NEWLINE# #INDENT# '\n        do the UNIX double-fork magic, see Stevens\' "Advanced\n        Programming in the UNIX Environment" for details (ISBN 0201563177)\n        http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16\n        ' #NEWLINE# try : #NEWLINE# #INDENT# pid = os . fork ( ) #NEWLINE# if ( pid > 0 ) : #NEWLINE# #INDENT# sys . exit ( 0 ) #NEWLINE# #UNINDENT# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# sys . stderr . write ( ( 'fork #1 failed: %d (%s)\n' % ( e . errno , e . strerror ) ) ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# os . chdir ( '/' ) #NEWLINE# os . setsid ( ) #NEWLINE# os . umask ( 0 ) #NEWLINE# try : #NEWLINE# #INDENT# pid = os . fork ( ) #NEWLINE# if ( pid > 0 ) : #NEWLINE# #INDENT# sys . exit ( 0 ) #NEWLINE# #UNINDENT# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# sys . stderr . write ( ( 'fork #2 failed: %d (%s)\n' % ( e . errno , e . strerror ) ) ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# sys . stdout . flush ( ) #NEWLINE# sys . stderr . flush ( ) #NEWLINE# si = file ( self . stdin , 'r' ) #NEWLINE# so = file ( self . stdout , 'a+' ) #NEWLINE# se = file ( self . stderr , 'a+' , 0 ) #NEWLINE# os . dup2 ( si . fileno ( ) , sys . stdin . fileno ( ) ) #NEWLINE# os . dup2 ( so . fileno ( ) , sys . stdout . fileno ( ) ) #NEWLINE# os . dup2 ( se . fileno ( ) , sys . stderr . fileno ( ) ) #NEWLINE# atexit . register ( self . delpid ) #NEWLINE# pid = str ( os . getpid ( ) ) #NEWLINE# file ( self . pidfile , 'w+' ) . write ( ( '%s\n' % pid ) )