diff options
author | Robert Brewer <fumanchu@aminus.org> | 2008-04-26 23:07:53 +0000 |
---|---|---|
committer | Robert Brewer <fumanchu@aminus.org> | 2008-04-26 23:07:53 +0000 |
commit | 1188a6e5f2a0577d0b1ef095e1bc088a9bd61885 (patch) | |
tree | dfc69f9bb4787bda779ea14901d1dc6ec09a64c2 | |
parent | 3add0e540482ffb5171a066b570cf30c403ba403 (diff) | |
download | cherrypy-1188a6e5f2a0577d0b1ef095e1bc088a9bd61885.tar.gz |
Fix for #806 (Move dead thread detection). Consumers can call shrink() anytime they want.
-rw-r--r-- | cherrypy/wsgiserver/__init__.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/cherrypy/wsgiserver/__init__.py b/cherrypy/wsgiserver/__init__.py index 3bfded43..0f93aa83 100644 --- a/cherrypy/wsgiserver/__init__.py +++ b/cherrypy/wsgiserver/__init__.py @@ -1091,12 +1091,6 @@ class ThreadPool(object): self._queue.put(obj) if obj is _SHUTDOWNREQUEST: return - - # Grow/shrink the pool if necessary. - # Remove any dead threads from our list - for t in self._threads: - if not t.isAlive(): - self._threads.remove(t) def grow(self, amount): """Spawn new worker threads (not above self.max).""" @@ -1110,12 +1104,20 @@ class ThreadPool(object): def shrink(self, amount): """Kill off worker threads (not below self.min).""" - for i in xrange(min(amount, len(self._threads) - self.min)): - # Put a number of shutdown requests on the queue equal - # to 'amount'. Once each of those is processed by a worker, - # that worker will terminate and be culled from our list - # in self.put. - self._queue.put(_SHUTDOWNREQUEST) + # Grow/shrink the pool if necessary. + # Remove any dead threads from our list + for t in self._threads: + if not t.isAlive(): + self._threads.remove(t) + amount -= 1 + + if amount > 0: + for i in xrange(min(amount, len(self._threads) - self.min)): + # Put a number of shutdown requests on the queue equal + # to 'amount'. Once each of those is processed by a worker, + # that worker will terminate and be culled from our list + # in self.put. + self._queue.put(_SHUTDOWNREQUEST) def stop(self, timeout=5): # Must shut down threads here so the code that calls |