I try to daemonize twisted, but it uses 100% cpu. The problem occurs in this code:
def daemonize(log_stdout=False, out_name=None, log_stderr=False, err_name=None): """ Turn current process into a daemon """ pid = os.fork() if (pid == 0): ## os.chdir (workdir) os.setsid() maxfd = os.sysconf("SC_OPEN_MAX") for fd in range(0, maxfd): try: os.close(fd) except OSError: # ERROR (ignore) pass # Redirect the standard file descriptors to /dev/null. <<<< HERE's THE PROBLEM os.open("/dev/null", os.O_RDONLY) # standard input (0) os.open("/dev/null", os.O_RDWR) # standard output (1) os.open("/dev/null", os.O_RDWR) # standard error (2) if (not out_name): out_name = gen_name() + '.out' if (not err_name): err_name = gen_name() + '.err' if (log_stdout): sys.stdout = logger.logger (out_name) if (log_stderr): sys.stderr = logger.logger (err_name) else: print "forked pid", pid sys.exit (0) If I comment out the lines that open /dev/null, everything is OK, but with those lines the process uses 100% cpu. The actual twisted code (not shown) is class Spawner(xmlrpc.XMLRPC): ... r = Spawner() reactor.listenTCP(7080, server.Site(r)) reactor.run() This is on linux. _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python