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

Ticket #691: multictrlc.patch

  • cherrypy/wsgiserver/__init__.py

    old new  
    4747quoted_slash = re.compile("(?i)%2F") 
    4848import rfc822 
    4949import socket 
     50import _socket 
    5051try: 
    5152    import cStringIO as StringIO 
    5253except ImportError: 
     
    673674    it is necessary to stick a _SHUTDOWNREQUEST object onto the Queue 
    674675    (one for each running WorkerThread). 
    675676    """ 
    676      
     677    conn = None 
     678 
    677679    def __init__(self, server): 
    678680        self.ready = False 
    679681        self.server = server 
     
    683685        try: 
    684686            self.ready = True 
    685687            while True: 
    686                 conn = self.server.requests.get() 
     688                conn = self.conn = self.server.requests.get() 
    687689                if conn is _SHUTDOWNREQUEST: 
    688690                    return 
    689691                 
     
    766768    ssl_private_key = None 
    767769     
    768770    def __init__(self, bind_addr, wsgi_app, numthreads=10, server_name=None, 
    769                  max=-1, request_queue_size=5, timeout=10): 
     771                 max=-1, request_queue_size=5, timeout=10, shutdown_timeout=3): 
    770772        self.requests = Queue.Queue(max) 
    771773         
    772774        if callable(wsgi_app): 
     
    790792        self._workerThreads = [] 
    791793         
    792794        self.timeout = timeout 
     795        self.shutdown_timeout = shutdown_timeout 
    793796     
    794797    def start(self): 
    795798        """Run the server forever.""" 
     
    968971         
    969972        # Don't join currentThread (when stop is called inside a request). 
    970973        current = threading.currentThread() 
     974 
     975 
    971976        while self._workerThreads: 
    972977            worker = self._workerThreads.pop() 
    973978            if worker is not current and worker.isAlive: 
    974979                try: 
    975                     worker.join() 
    976                 except AssertionError: 
     980                    worker.join(self.shutdown_timeout) 
     981                    if worker.isAlive: 
     982                        # We exhausted the timeout. 
     983                        # Forcibly shut down the socket. 
     984                        c = worker.conn 
     985                        if c and not c.rfile.closed: 
     986                            c.rfile._sock.shutdown(_socket.SHUT_RDWR) 
     987                except (AssertionError, KeyboardInterrupt): 
    977988                    pass 
    978989     
    979990    def populate_ssl_environ(self): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets