Denis Bilenko committed 64e4824

ThreadPool: fix _set_size to stop _fork_watcher if it's not needed; also make sure it does not try to sleep when run inside hub

Comments (0)

Files changed (1)


 from __future__ import with_statement
 import sys
 import os
-from gevent.hub import get_hub, sleep, integer_types
+from gevent.hub import get_hub, getcurrent, sleep, integer_types
 from gevent.event import AsyncResult
 from gevent.greenlet import Greenlet
 from gevent.pool import IMap, IMapUnordered
         while self._size > size:
             while self._size - size > self.task_queue.unfinished_tasks:
+            if getcurrent() is self.hub:
+                break
             delay = min(delay * 2, .05)
+        if self._size:
+            self.fork_watcher.start(self._on_fork)
+        else:
+            self.fork_watcher.stop()
     size = property(_get_size, _set_size)