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

Changeset 1660

Show
Ignore:
Timestamp:
06/06/07 17:30:12
Author:
fumanchu
Message:

Fix for #691 (Repeated Ctrl-C hangs wsgiserver). It took a bit of doing, but test_states passes on my box. If others can try test_states with and without the -ssl flag, that would be a big help.

Files:

Legend:

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

    r1627 r1660  
    4545    socket_queue_size = 5 
    4646    socket_timeout = 10 
     47    shutdown_timeout = 5 
    4748    protocol_version = 'HTTP/1.1' 
    4849    reverse_dns = False 
  • trunk/cherrypy/_cpwsgi.py

    r1627 r1660  
    372372                   request_queue_size = server.socket_queue_size, 
    373373                   timeout = server.socket_timeout, 
     374                   shutdown_timeout = server.shutdown_timeout, 
    374375                   ) 
    375376        self.protocol = server.protocol_version 
  • trunk/cherrypy/test/test_states.py

    r1627 r1660  
    4444    'environment': 'test_suite', 
    4545    'engine.deadlock_poll_freq': 0.1, 
    46     'response.timeout': 0.2, 
    4746    }) 
    4847 
     
    215214     
    216215    def test_3_Deadlocks(self): 
     216        cherrypy.config.update({'response.timeout': 0.2}) 
     217         
    217218        cherrypy.engine.start() 
    218219        cherrypy.server.start() 
  • trunk/cherrypy/wsgiserver/__init__.py

    r1627 r1660  
    675675    """ 
    676676     
     677    conn = None 
     678     
    677679    def __init__(self, server): 
    678680        self.ready = False 
     
    688690                    return 
    689691                 
     692                self.conn = conn 
    690693                try: 
    691694                    conn.communicate() 
    692695                finally: 
    693696                    conn.close() 
     697                    self.conn = None 
    694698        except (KeyboardInterrupt, SystemExit), exc: 
    695699            self.server.interrupt = exc 
     
    767771     
    768772    def __init__(self, bind_addr, wsgi_app, numthreads=10, server_name=None, 
    769                  max=-1, request_queue_size=5, timeout=10): 
     773                 max=-1, request_queue_size=5, timeout=10, shutdown_timeout=5): 
    770774        self.requests = Queue.Queue(max) 
    771775         
     
    791795         
    792796        self.timeout = timeout 
     797        self.shutdown_timeout = shutdown_timeout 
    793798     
    794799    def start(self): 
     
    872877                    # Wait for self.stop() to complete. See _set_interrupt. 
    873878                    time.sleep(0.1) 
    874                 raise self.interrupt 
     879                if self.interrupt: 
     880                    raise self.interrupt 
    875881     
    876882    def bind(self, family, type, proto=0): 
     
    969975        # Don't join currentThread (when stop is called inside a request). 
    970976        current = threading.currentThread() 
     977        timeout = self.shutdown_timeout 
    971978        while self._workerThreads: 
    972979            worker = self._workerThreads.pop() 
    973980            if worker is not current and worker.isAlive: 
    974981                try: 
    975                     worker.join() 
    976                 except AssertionError: 
     982                    if timeout is None or timeout < 0: 
     983                        worker.join() 
     984                    else: 
     985                        worker.join(timeout) 
     986                        if worker.isAlive: 
     987                            # We exhausted the timeout. 
     988                            # Forcibly shut down the socket. 
     989                            c = worker.conn 
     990                            if c and not c.rfile.closed: 
     991                                if SSL and isinstance(c.socket, SSL.ConnectionType): 
     992                                    # pyOpenSSL.socket.shutdown takes no args 
     993                                    c.socket.shutdown() 
     994                                else: 
     995                                    c.socket.shutdown(socket.SHUT_RD) 
     996                            worker.join() 
     997                except (AssertionError, 
     998                        # Ignore repeated Ctrl-C. 
     999                        # See http://www.cherrypy.org/ticket/691. 
     1000                        KeyboardInterrupt), exc1: 
     1001                    print exc1 
    9771002                    pass 
    9781003     

Hosted by WebFaction

Log in as guest/cpguest to create tickets