Changeset 1835
- Timestamp:
- 11/27/07 11:58:14
- Files:
-
- trunk/cherrypy/restsrv/plugins.py (modified) (3 diffs)
- trunk/cherrypy/test/test_states.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/restsrv/plugins.py
r1833 r1835 197 197 198 198 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. 200 205 """ 201 206 … … 239 244 # This is the first parent. Exit, now that we've forked. 240 245 self.bus.log('Forking once.') 241 sys.exit(0)246 os._exit(0) 242 247 except OSError, exc: 243 248 # Python raises OSError rather than returning negative numbers. … … 252 257 if pid > 0: 253 258 self.bus.log('Forking twice.') 254 sys.exit(0) # Exit second parent259 os._exit(0) # Exit second parent 255 260 except OSError, exc: 256 261 sys.exit("%s: fork #2 failed: (%d) %s\n" trunk/cherrypy/test/test_states.py
r1830 r1835 380 380 if exit_code != 0: 381 381 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 return387 if os.name not in ['posix']:388 print "skipped (not on posix) ",389 return390 391 # Start the demo script in a new process392 demoscript = os.path.join(os.getcwd(), os.path.dirname(__file__),393 "test_states_demo.py")394 host = cherrypy.server.socket_host395 port = cherrypy.server.socket_port396 397 # If a process errors during start, it should stop the engine398 # and exit with a non-zero exit code, even if we daemonize soon399 # 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.407 382 408 383

