|
@@ -3,7 +3,7 @@
|
|
Process Pools.
|
|
Process Pools.
|
|
|
|
|
|
"""
|
|
"""
|
|
-from billiard.pool import Pool
|
|
|
|
|
|
+from billiard.pool import Pool, RUN
|
|
from billiard.utils.functional import curry
|
|
from billiard.utils.functional import curry
|
|
|
|
|
|
from celery import log
|
|
from celery import log
|
|
@@ -43,17 +43,18 @@ class TaskPool(object):
|
|
Will pre-fork all workers so they're ready to accept tasks.
|
|
Will pre-fork all workers so they're ready to accept tasks.
|
|
|
|
|
|
"""
|
|
"""
|
|
- self._pool = DynamicPool(processes=self.limit,
|
|
|
|
- initializer=self.initializer,
|
|
|
|
- timeout=self.timeout,
|
|
|
|
- soft_timeout=self.soft_timeout,
|
|
|
|
- maxtasksperchild=self.maxtasksperchild)
|
|
|
|
|
|
+ self._pool = Pool(processes=self.limit,
|
|
|
|
+ initializer=self.initializer,
|
|
|
|
+ timeout=self.timeout,
|
|
|
|
+ soft_timeout=self.soft_timeout,
|
|
|
|
+ maxtasksperchild=self.maxtasksperchild)
|
|
|
|
|
|
def stop(self):
|
|
def stop(self):
|
|
"""Terminate the pool."""
|
|
"""Terminate the pool."""
|
|
- self._pool.close()
|
|
|
|
- self._pool.join()
|
|
|
|
- self._pool = None
|
|
|
|
|
|
+ if self._pool is not None and self._pool._state == RUN:
|
|
|
|
+ self._pool.close()
|
|
|
|
+ self._pool.join()
|
|
|
|
+ self._pool = None
|
|
|
|
|
|
def apply_async(self, target, args=None, kwargs=None, callbacks=None,
|
|
def apply_async(self, target, args=None, kwargs=None, callbacks=None,
|
|
errbacks=None, accept_callback=None, timeout_callback=None,
|
|
errbacks=None, accept_callback=None, timeout_callback=None,
|