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

Changeset 1999

Show
Ignore:
Timestamp:
06/29/08 13:20:51
Author:
fumanchu
Message:

Fixed sig handler unsubscribe test for Unix, plus an odd race condition in autoreload.

Files:

Legend:

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

    r1998 r1999  
    7171     
    7272    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
    7575             
    7676            if handler is None: 
     
    8181             
    8282            try: 
    83                 _signal.signal(sig, handler) 
     83                _signal.signal(signum, handler) 
    8484            except ValueError: 
    8585                self.bus.log("Unable to restore %s handler %r." % 
    86                              (signame, handler)
     86                             (signame, handler), traceback=True
    8787     
    8888    def set_handler(self, signal, listener=None): 
     
    398398        else: 
    399399            if self.thread is not threading.currentThread(): 
     400                name = self.thread.getName() 
    400401                self.thread.cancel() 
    401402                self.thread.join() 
    402                 self.bus.log("Stopped thread %r." % self.thread.getName()
     403                self.bus.log("Stopped thread %r." % name
    403404            self.thread = None 
    404405     
  • trunk/cherrypy/test/test_states.py

    r1998 r1999  
    1616 
    1717 
    18 def write_conf(scheme='http', starterror=False): 
     18def write_conf(scheme='http', extra=""): 
    1919    if scheme.lower() == 'https': 
    2020        serverpem = os.path.join(thisdir, 'test.pem') 
     
    2626        ssl = "" 
    2727     
    28     if starterror: 
    29         starterror = "starterror: True" 
    30     else: 
    31         starterror = "" 
    32      
    3328    conffile = open(os.path.join(thisdir, 'test_states.conf'), 'wb') 
    3429    conffile.write("""[global] 
     
    3934log.access_file: r'%(access_log)s' 
    4035%(ssl)s 
    41 %(starterror)s 
     36%(extra)s 
    4237""" % {'host': host, 
    4338       'port': port, 
     
    4540       'access_log': os.path.join(thisdir, 'test_states_demo.access.log'), 
    4641       'ssl': ssl, 
    47        'starterror': starterror
     42       'extra': extra
    4843       }) 
    4944    conffile.close() 
     
    380375        # If a process errors during start, it should stop the engine 
    381376        # 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"
    383378        exit_code = spawn_cp(wait=True) 
    384379        if exit_code == 0: 
     
    534529         
    535530        # Spawn a normal, undaemonized process. 
    536         write_conf(scheme=self.scheme
     531        write_conf(scheme=self.scheme, extra="unsubsig: True"
    537532        pid = spawn_cp(wait=False, daemonize=False) 
    538         self.getPage("/unsub_sig") 
    539         self.assertBody("OK") 
    540533        os.kill(pid, SIGTERM) 
    541534        wait(pid) 
    542535        # Assert the old handler ran. 
    543536        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) 
    546540 
    547541 
  • trunk/cherrypy/test/test_states_demo.py

    r1998 r1999  
    3434    exit.exposed = True 
    3535     
    36     def unsub_sig(self): 
    37         cherrypy.engine.signal_handler.unsubscribe() 
    38         return "OK" 
    39     unsub_sig.exposed = True 
    40  
    4136try: 
    42     from signal import SIGTERM 
     37    from signal import signal, SIGTERM 
    4338except ImportError: 
    4439    pass 
     
    4641    def old_term_handler(signum=None, frame=None): 
    4742        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 
     46def unsub_sig(): 
     47    if cherrypy.config.get('unsubsig', False): 
     48        cherrypy.engine.signal_handler.unsubscribe() 
     49cherrypy.engine.subscribe('start', unsub_sig, priority=100) 
    4950 
    5051 
     
    5455cherrypy.engine.subscribe('start', starterror, priority=6) 
    5556 
     57 
    5658cherrypy.tree.mount(Root(), '/', {'/': {}}) 

Hosted by WebFaction

Log in as guest/cpguest to create tickets