Ticket #691: multictrlc.patch
-
cherrypy/wsgiserver/__init__.py
old new 47 47 quoted_slash = re.compile("(?i)%2F") 48 48 import rfc822 49 49 import socket 50 import _socket 50 51 try: 51 52 import cStringIO as StringIO 52 53 except ImportError: … … 673 674 it is necessary to stick a _SHUTDOWNREQUEST object onto the Queue 674 675 (one for each running WorkerThread). 675 676 """ 676 677 conn = None 678 677 679 def __init__(self, server): 678 680 self.ready = False 679 681 self.server = server … … 683 685 try: 684 686 self.ready = True 685 687 while True: 686 conn = self. server.requests.get()688 conn = self.conn = self.server.requests.get() 687 689 if conn is _SHUTDOWNREQUEST: 688 690 return 689 691 … … 766 768 ssl_private_key = None 767 769 768 770 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): 770 772 self.requests = Queue.Queue(max) 771 773 772 774 if callable(wsgi_app): … … 790 792 self._workerThreads = [] 791 793 792 794 self.timeout = timeout 795 self.shutdown_timeout = shutdown_timeout 793 796 794 797 def start(self): 795 798 """Run the server forever.""" … … 968 971 969 972 # Don't join currentThread (when stop is called inside a request). 970 973 current = threading.currentThread() 974 975 971 976 while self._workerThreads: 972 977 worker = self._workerThreads.pop() 973 978 if worker is not current and worker.isAlive: 974 979 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): 977 988 pass 978 989 979 990 def populate_ssl_environ(self):

