<s> import sys , os <EOL> __version__ = '<STR_LIT>' <EOL> is_daemon = False <EOL> def daemonize ( close_fd = True , chdir = True , write_pid = False , redirect_std = None ) : <EOL> """<STR_LIT>""" <EOL> if not os . fork ( ) : <EOL> os . setsid ( ) <EOL> pid = os . fork ( ) <EOL> if not pid : <EOL> global is_daemon <EOL> is_daemon = True <EOL> if close_fd : <EOL> os . close ( <NUM_LIT:0> ) <EOL> os . close ( <NUM_LIT:1> ) <EOL> os . close ( <NUM_LIT:2> ) <EOL> os . open ( '<STR_LIT>' , os . O_RDWR ) <EOL> if redirect_std : <EOL> os . open ( redirect_std , os . O_WRONLY | os . O_APPEND ) <EOL> else : <EOL> os . dup2 ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> os . dup2 ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> if chdir : <EOL> os . chdir ( '<STR_LIT:/>' ) <EOL> return <EOL> else : <EOL> f = open ( os . path . basename ( sys . argv [ <NUM_LIT:0> ] ) + '<STR_LIT>' , '<STR_LIT:w>' ) <EOL> f . write ( str ( pid ) ) <EOL> f . close ( ) <EOL> os . _exit ( <NUM_LIT:0> ) <EOL> else : <EOL> os . _exit ( <NUM_LIT:0> ) </s>
