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

Changeset 1758

Show
Ignore:
Timestamp:
10/18/07 21:43:38
Author:
fumanchu
Message:

Bus docs, plus dropping the 'restart' channel in favor of calling 'exit' on restart.

Files:

Legend:

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

    r1752 r1758  
    302302    elif k == 'deadlock_poll_freq': 
    303303        cherrypy.timeout_monitor.frequency = v 
    304     elif k == 'reexec_retry': 
    305         engine.publish('restart', 'retry', v) 
    306304    elif k == 'SIGHUP': 
    307305        engine.listeners['SIGHUP'] = set([v]) 
  • trunk/cherrypy/restsrv/wspbus.py

    r1757 r1758  
    3636The Bus object in this package uses topic-based publish-subscribe 
    3737messaging to accomplish all this. A few topic channels are built in 
    38 ('start', 'stop', 'exit', 'restart' and 'graceful'). Frameworks and 
    39 site containers are free to define their own. If a message is sent to a 
    40 channel that has not been defined or has no listeners, there is no effect. 
     38('start', 'stop', 'exit', and 'graceful'). Frameworks and site containers 
     39are free to define their own. If a message is sent to a channel that has 
     40not been defined or has no listeners, there is no effect. 
    4141 
    4242In general, there should only ever be a single Bus object per process. 
     
    4848those methods then publish to subscribed listeners on the channel for 
    4949the new state. 
     50 
     51                        O 
     52                        | 
     53                        V 
     54       STOPPING --> STOPPED --> X 
     55          A   A         | 
     56          |    \___     | 
     57          |        \    | 
     58          |         V   V 
     59        STARTED <-- STARTING 
     60 
    5061""" 
    5162 
     63import os 
    5264try: 
    5365    set 
     
    5870import time 
    5971import traceback as _traceback 
    60 import os 
    61 import exceptions 
     72 
    6273 
    6374# Use a flag to indicate the state of the bus. 
     
    7788    states = states 
    7889    state = states.STOPPED 
     90    execv = False 
    7991     
    8092    def __init__(self): 
     
    8395        self.listeners = dict( 
    8496            [(channel, set()) for channel 
    85              in ('start', 'stop', 'exit', 'restart', 'graceful')]) 
     97             in ('start', 'stop', 'exit', 'graceful')]) 
    8698        self._priorities = {} 
    8799     
     
    142154        """Stop all services and exit the process.""" 
    143155        self.stop() 
    144          
    145156        self.log('Bus exit') 
    146157        self.publish('exit') 
     
    148159     
    149160    def restart(self): 
    150         """Restart the process (may close connections).""" 
    151         if self.execv: 
    152             raise exceptions.AssertionError("Already restarting.") 
    153  
     161        """Restart the process (may close connections). 
     162         
     163        This method does not restart the process from the calling thread; 
     164        instead, it stops the bus and asks the main thread to call execv. 
     165        """ 
    154166        self.execv = True 
    155167        self.stop() 
    156          
    157         self.log('Bus restart') 
    158         self.publish('restart') 
    159168     
    160169    def graceful(self): 
     
    182191    def _do_execv(self): 
    183192        """Re-execute the current process.""" 
    184         # Waiting for the child threads to finish is necessary on OS X. 
     193        self.execv = False 
     194         
     195        self.log('Bus restart') 
     196        self.publish('exit') 
     197         
     198        # Re-execute the current process. We must do this in the 
     199        # main thread (which is the only thread that should be 
     200        # calling block) because OS X doesn't allow execv to be 
     201        # called in a child thread very well. 
     202        # Waiting for ALL child threads to finish is necessary on OS X. 
    185203        # See: http://www.cherrypy.org/ticket/581 
    186         self.log("Waiting for child threads...") 
    187         threads = [t for t in threading.enumerate() if t != threading.currentThread()] 
    188         for t in threads
    189             t.join() 
    190  
     204        self.log("Waiting for child threads to terminate...") 
     205        for t in threading.enumerate(): 
     206            if t != threading.currentThread()
     207                t.join() 
     208         
    191209        args = sys.argv[:] 
    192210        self.log('Re-spawning %s' % ' '.join(args)) 
    193211        args.insert(0, sys.executable) 
    194  
     212         
    195213        if sys.platform == 'win32': 
    196214            args = ['"%s"' % arg for arg in args] 
    197  
     215         
    198216        os.execv(sys.executable, args) 
    199  
    200  
     217     
    201218    def stop(self): 
    202219        """Stop all services.""" 

Hosted by WebFaction

Log in as guest/cpguest to create tickets