|
@@ -13,6 +13,7 @@ __all__ = ['Pool']
|
|
#
|
|
#
|
|
|
|
|
|
import os
|
|
import os
|
|
|
|
+import sys
|
|
import errno
|
|
import errno
|
|
import threading
|
|
import threading
|
|
import Queue
|
|
import Queue
|
|
@@ -22,6 +23,7 @@ import time
|
|
import signal
|
|
import signal
|
|
|
|
|
|
from multiprocessing import Process, cpu_count, TimeoutError
|
|
from multiprocessing import Process, cpu_count, TimeoutError
|
|
|
|
+from multiprocessing import util
|
|
from multiprocessing.util import Finalize, debug
|
|
from multiprocessing.util import Finalize, debug
|
|
|
|
|
|
from celery.exceptions import SoftTimeLimitExceeded, TimeLimitExceeded
|
|
from celery.exceptions import SoftTimeLimitExceeded, TimeLimitExceeded
|
|
@@ -58,6 +60,11 @@ def mapstar(args):
|
|
return map(*args)
|
|
return map(*args)
|
|
|
|
|
|
|
|
|
|
|
|
+def error(msg, *args, **kwargs):
|
|
|
|
+ if util._logger:
|
|
|
|
+ util._logger.error(msg, *args, **kwargs)
|
|
|
|
+
|
|
|
|
+
|
|
class LaxBoundedSemaphore(threading._Semaphore):
|
|
class LaxBoundedSemaphore(threading._Semaphore):
|
|
"""Semaphore that checks that # release is <= # acquires,
|
|
"""Semaphore that checks that # release is <= # acquires,
|
|
but ignores if # releases >= value."""
|
|
but ignores if # releases >= value."""
|
|
@@ -168,6 +175,14 @@ class PoolThread(threading.Thread):
|
|
self._state = RUN
|
|
self._state = RUN
|
|
self.daemon = True
|
|
self.daemon = True
|
|
|
|
|
|
|
|
+ def run(self):
|
|
|
|
+ try:
|
|
|
|
+ return self.body()
|
|
|
|
+ except Exception, exc:
|
|
|
|
+ error("Thread %r crashed: %r" % (self.__class__.__name__, exc, ),
|
|
|
|
+ exc_info=sys.exc_info())
|
|
|
|
+ os._exit(1)
|
|
|
|
+
|
|
def terminate(self):
|
|
def terminate(self):
|
|
self._state = TERMINATE
|
|
self._state = TERMINATE
|
|
|
|
|
|
@@ -181,7 +196,7 @@ class Supervisor(PoolThread):
|
|
self.pool = pool
|
|
self.pool = pool
|
|
super(Supervisor, self).__init__()
|
|
super(Supervisor, self).__init__()
|
|
|
|
|
|
- def run(self):
|
|
|
|
|
|
+ def body(self):
|
|
debug('worker handler starting')
|
|
debug('worker handler starting')
|
|
while self._state == RUN and self.pool._state == RUN:
|
|
while self._state == RUN and self.pool._state == RUN:
|
|
self.pool._maintain_pool()
|
|
self.pool._maintain_pool()
|
|
@@ -198,7 +213,7 @@ class TaskHandler(PoolThread):
|
|
self.pool = pool
|
|
self.pool = pool
|
|
super(TaskHandler, self).__init__()
|
|
super(TaskHandler, self).__init__()
|
|
|
|
|
|
- def run(self):
|
|
|
|
|
|
+ def body(self):
|
|
taskqueue = self.taskqueue
|
|
taskqueue = self.taskqueue
|
|
outqueue = self.outqueue
|
|
outqueue = self.outqueue
|
|
put = self.put
|
|
put = self.put
|
|
@@ -249,7 +264,7 @@ class TimeoutHandler(PoolThread):
|
|
self.putlock = putlock
|
|
self.putlock = putlock
|
|
super(TimeoutHandler, self).__init__()
|
|
super(TimeoutHandler, self).__init__()
|
|
|
|
|
|
- def run(self):
|
|
|
|
|
|
+ def body(self):
|
|
processes = self.processes
|
|
processes = self.processes
|
|
cache = self.cache
|
|
cache = self.cache
|
|
putlock = self.putlock
|
|
putlock = self.putlock
|
|
@@ -338,7 +353,7 @@ class ResultHandler(PoolThread):
|
|
self.putlock = putlock
|
|
self.putlock = putlock
|
|
super(ResultHandler, self).__init__()
|
|
super(ResultHandler, self).__init__()
|
|
|
|
|
|
- def run(self):
|
|
|
|
|
|
+ def body(self):
|
|
get = self.get
|
|
get = self.get
|
|
outqueue = self.outqueue
|
|
outqueue = self.outqueue
|
|
cache = self.cache
|
|
cache = self.cache
|