Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1835

Show
Ignore:
Timestamp:
11/27/07 11:58:14
Author:
lakin
Message:

Parent processes in Daemonizer should not even attempt to clean up after themselves, so use os._exit(0) instead of sys.exit(0). Updated tests and documentation to reflect the fact that if the first forkin Daemonizer completes, the process return code will always be 0.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/restsrv/plugins.py

    r1833 r1835  
    197197     
    198198    When this component finishes, the process is completely decoupled from 
    199     the parent environment. 
     199    the parent environment.  Please note that when this component is used, 
     200    the return code from the parent process will always be 0, even if a 
     201    startup error occured, unless that error was during the daemonizing process.  
     202    If you use this plugin to Daemonize, don't use the return code as an accurate 
     203    indication of whether the process fully started.  In fact, that return code 
     204    only indicates if the process succesfully finished the first fork. 
    200205    """ 
    201206     
     
    239244                # This is the first parent. Exit, now that we've forked. 
    240245                self.bus.log('Forking once.') 
    241                 sys.exit(0) 
     246                os._exit(0) 
    242247        except OSError, exc: 
    243248            # Python raises OSError rather than returning negative numbers. 
     
    252257            if pid > 0: 
    253258                self.bus.log('Forking twice.') 
    254                 sys.exit(0) # Exit second parent 
     259                os._exit(0) # Exit second parent 
    255260        except OSError, exc: 
    256261            sys.exit("%s: fork #2 failed: (%d) %s\n" 
  • trunk/cherrypy/test/test_states.py

    r1830 r1835  
    380380        if exit_code != 0: 
    381381            self.fail("Daemonized process failed to exit cleanly") 
    382      
    383     def test_2_Start_Error_With_Daemonize(self): 
    384         if not self.server_class: 
    385             print "skipped (no server) ", 
    386             return 
    387         if os.name not in ['posix']:  
    388             print "skipped (not on posix) ", 
    389             return 
    390          
    391         # Start the demo script in a new process 
    392         demoscript = os.path.join(os.getcwd(), os.path.dirname(__file__), 
    393                                   "test_states_demo.py") 
    394         host = cherrypy.server.socket_host 
    395         port = cherrypy.server.socket_port 
    396          
    397         # If a process errors during start, it should stop the engine 
    398         # and exit with a non-zero exit code, even if we daemonize soon 
    399         # thereafter. 
    400         args = [sys.executable, demoscript, host, str(port), '-starterror', '-daemonize'] 
    401         if self.scheme == "https": 
    402             args.append('-ssl') 
    403         exit_code = os.spawnl(os.P_WAIT, sys.executable, *args) 
    404         if exit_code == 0: 
    405             self.fail("Process failed to return nonzero exit code.") 
    406         time.sleep(2) # Wait for the daemonized process to exit. 
    407382 
    408383 

Hosted by WebFaction

Log in as guest/cpguest to create tickets