Changeset 1999
- Timestamp:
- 06/29/08 13:20:51
- Files:
-
- trunk/cherrypy/process/plugins.py (modified) (3 diffs)
- trunk/cherrypy/test/test_states.py (modified) (6 diffs)
- trunk/cherrypy/test/test_states_demo.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/process/plugins.py
r1998 r1999 71 71 72 72 def unsubscribe(self): 73 for sig , handler in self._previous_handlers.iteritems():74 signame = self.signals[sig ]73 for signum, handler in self._previous_handlers.iteritems(): 74 signame = self.signals[signum] 75 75 76 76 if handler is None: … … 81 81 82 82 try: 83 _signal.signal(sig , handler)83 _signal.signal(signum, handler) 84 84 except ValueError: 85 85 self.bus.log("Unable to restore %s handler %r." % 86 (signame, handler) )86 (signame, handler), traceback=True) 87 87 88 88 def set_handler(self, signal, listener=None): … … 398 398 else: 399 399 if self.thread is not threading.currentThread(): 400 name = self.thread.getName() 400 401 self.thread.cancel() 401 402 self.thread.join() 402 self.bus.log("Stopped thread %r." % self.thread.getName())403 self.bus.log("Stopped thread %r." % name) 403 404 self.thread = None 404 405 trunk/cherrypy/test/test_states.py
r1998 r1999 16 16 17 17 18 def write_conf(scheme='http', starterror=False):18 def write_conf(scheme='http', extra=""): 19 19 if scheme.lower() == 'https': 20 20 serverpem = os.path.join(thisdir, 'test.pem') … … 26 26 ssl = "" 27 27 28 if starterror:29 starterror = "starterror: True"30 else:31 starterror = ""32 33 28 conffile = open(os.path.join(thisdir, 'test_states.conf'), 'wb') 34 29 conffile.write("""[global] … … 39 34 log.access_file: r'%(access_log)s' 40 35 %(ssl)s 41 %( starterror)s36 %(extra)s 42 37 """ % {'host': host, 43 38 'port': port, … … 45 40 'access_log': os.path.join(thisdir, 'test_states_demo.access.log'), 46 41 'ssl': ssl, 47 ' starterror': starterror,42 'extra': extra, 48 43 }) 49 44 conffile.close() … … 380 375 # If a process errors during start, it should stop the engine 381 376 # and exit with a non-zero exit code. 382 write_conf(scheme=self.scheme, starterror=True)377 write_conf(scheme=self.scheme, extra="starterror: True") 383 378 exit_code = spawn_cp(wait=True) 384 379 if exit_code == 0: … … 534 529 535 530 # Spawn a normal, undaemonized process. 536 write_conf(scheme=self.scheme )531 write_conf(scheme=self.scheme, extra="unsubsig: True") 537 532 pid = spawn_cp(wait=False, daemonize=False) 538 self.getPage("/unsub_sig")539 self.assertBody("OK")540 533 os.kill(pid, SIGTERM) 541 534 wait(pid) 542 535 # Assert the old handler ran. 543 536 errlog = os.path.join(thisdir, 'test_states_demo.error.log') 544 self.assertEqual(open(errlog, 'rb').readlines()[-1], 545 "I am an old SIGTERM handler.") 537 target_line = open(errlog, 'rb').readlines()[-10] 538 if not "I am an old SIGTERM handler." in target_line: 539 self.fail("Old SIGTERM handler did not run.\n%r" % target_line) 546 540 547 541 trunk/cherrypy/test/test_states_demo.py
r1998 r1999 34 34 exit.exposed = True 35 35 36 def unsub_sig(self):37 cherrypy.engine.signal_handler.unsubscribe()38 return "OK"39 unsub_sig.exposed = True40 41 36 try: 42 from signal import SIGTERM37 from signal import signal, SIGTERM 43 38 except ImportError: 44 39 pass … … 46 41 def old_term_handler(signum=None, frame=None): 47 42 cherrypy.log("I am an old SIGTERM handler.") 48 _signal.signal(SIGTERM, old_term_handler) 43 sys.exit(0) 44 signal(SIGTERM, old_term_handler) 45 46 def unsub_sig(): 47 if cherrypy.config.get('unsubsig', False): 48 cherrypy.engine.signal_handler.unsubscribe() 49 cherrypy.engine.subscribe('start', unsub_sig, priority=100) 49 50 50 51 … … 54 55 cherrypy.engine.subscribe('start', starterror, priority=6) 55 56 57 56 58 cherrypy.tree.mount(Root(), '/', {'/': {}})

