Changeset 1755
- Timestamp:
- 10/18/07 16:59:36
- Files:
-
- trunk/cherrypy/restsrv/plugins.py (modified) (1 diff)
- trunk/cherrypy/test/test_states.py (modified) (10 diffs)
- trunk/cherrypy/test/test_states_demo.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/restsrv/plugins.py
r1754 r1755 412 412 self.threads = {} 413 413 self.bus = bus 414 self.bus.listeners.setdefault('acquire_thread', set()) 415 self.bus.listeners.setdefault('release_thread', set()) 414 416 415 417 def acquire_thread(self): trunk/cherrypy/test/test_states.py
r1743 r1755 13 13 engine = cherrypy.engine 14 14 thisdir = os.path.join(os.getcwd(), os.path.dirname(__file__)) 15 PID_file_path = os.path.join(thisdir,'pid_for_test_daemonize') 15 PID_file_path = os.path.join(thisdir, 'pid_for_test_daemonize') 16 16 17 17 18 class Root: … … 50 51 class Dependency: 51 52 52 def __init__(self): 53 def __init__(self, bus): 54 self.bus = bus 53 55 self.running = False 54 56 self.startcount = 0 … … 56 58 self.threads = {} 57 59 60 def subscribe(self): 61 self.bus.subscribe('start', self.start) 62 self.bus.subscribe('stop', self.stop) 63 self.bus.subscribe('graceful', self.graceful) 64 self.bus.subscribe('start_thread', self.startthread) 65 self.bus.subscribe('stop_thread', self.stopthread) 66 58 67 def start(self): 59 68 self.running = True … … 71 80 def stopthread(self, thread_id): 72 81 del self.threads[thread_id] 82 83 db_connection = Dependency(engine) 84 db_connection.subscribe() 73 85 74 86 … … 219 231 cherrypy.server.start() 220 232 try: 221 self.assertNotEqual(cherrypy. _timeout_monitor.thread, None)233 self.assertNotEqual(cherrypy.timeout_monitor.thread, None) 222 234 223 235 # Request a "normal" page. 224 self.assertEqual(cherrypy. _timeout_monitor.servings, [])236 self.assertEqual(cherrypy.timeout_monitor.servings, []) 225 237 self.getPage("/") 226 238 self.assertBody("Hello World") 227 239 # request.close is called async. 228 while cherrypy. _timeout_monitor.servings:240 while cherrypy.timeout_monitor.servings: 229 241 print ".", 230 242 time.sleep(0.01) … … 296 308 raise 297 309 310 298 311 class DaemonizeTest(helper.CPWebCase): 299 def test_0_Daemonize(self): 312 313 def test_Daemonize(self): 300 314 if not self.server_class: 301 315 print "skipped (no server) ", … … 304 318 print "skipped (not on posix) ", 305 319 return 306 307 320 308 321 # Start the demo script in a new process 309 322 demoscript = os.path.join(os.getcwd(), os.path.dirname(__file__), … … 321 334 exit_code = os.spawnl(os.P_WAIT, sys.executable, *args) 322 335 cherrypy._cpserver.wait_for_occupied_port(host, port) 323 336 324 337 # Give the server some time to start up 325 338 time.sleep(2) 326 339 327 340 # Get the PID from the file. 328 341 pid = int(open(PID_file_path).read()) … … 342 355 if x.args != (10, 'No child processes'): 343 356 raise 344 357 345 358 # Wait until here to test the exit code because we want to ensure 346 359 # that we wait for the daemon to finish running before we fail. 347 360 if exit_code != 0: 348 361 self.fail("Daemonized process failed to exit cleanly") 349 db_connection = None 362 350 363 351 364 def run(server, conf): … … 356 369 daemon_suite = helper.CPTestLoader.loadTestsFromTestCase(DaemonizeTest) 357 370 try: 358 global db_connection359 db_connection = Dependency()360 engine.subscribe('start', db_connection.start)361 engine.subscribe('stop', db_connection.stop)362 engine.subscribe('graceful', db_connection.graceful)363 engine.subscribe('start_thread', db_connection.startthread)364 engine.subscribe('stop_thread', db_connection.stopthread)365 366 371 try: 367 372 import pyconquer trunk/cherrypy/test/test_states_demo.py
r1745 r1755 5 5 6 6 import cherrypy 7 from cherrypy.restsrv .plugins import daemonize, PIDFile7 from cherrypy.restsrv import plugins 8 8 thisdir = os.path.join(os.getcwd(), os.path.dirname(__file__)) 9 PID_file_path = os.path.join(thisdir,'pid_for_test_daemonize') 9 PID_file_path = os.path.join(thisdir, 'pid_for_test_daemonize') 10 10 11 11 12 class Root: … … 55 56 raise SystemExit(1) 56 57 sys.exitfunc = exitfunc 57 58 cherrypy.engine.subscribe('start', daemonize)59 p id_file = PIDFile(cherrypy.engine, PID_file_path)60 58 59 plugins.Daemonizer(cherrypy.engine).subscribe() 60 plugins.PIDFile(cherrypy.engine, PID_file_path).subscribe() 61 61 62 cherrypy.engine.subscribe('start', cherrypy.server.quickstart) 62 63 63 64 # This is in a special order for a reason: 64 65 # it allows test_states to wait_for_occupied_port

