def process_initializer(app, hostname): """Pool child process initializer.""" platforms.signals.reset(*WORKER_SIGRESET) platforms.signals.ignore(*WORKER_SIGIGNORE) platforms.set_mp_process_title("celeryd", hostname=hostname) # This is for Windows and other platforms not supporting # fork(). Note that init_worker makes sure it's only # run once per process. app.loader.init_worker() app.loader.init_worker_process() app.log.setup( int(os.environ.get("CELERY_LOG_LEVEL", 0)), os.environ.get("CELERY_LOG_FILE") or None, bool(os.environ.get("CELERY_LOG_REDIRECT", False)), str(os.environ.get("CELERY_LOG_REDIRECT_LEVEL")), ) if os.environ.get("FORKED_BY_MULTIPROCESSING"): # pool did execv after fork trace.setup_worker_optimizations(app) else: app.set_current() set_default_app(app) app.finalize() trace._tasks = app._tasks # enables fast_trace_task optimization. from celery.task.trace import build_tracer for name, task in items(app.tasks): task.__trace__ = build_tracer(name, task, app.loader, hostname) signals.worker_process_init.send(sender=None)
def process_initializer(app, hostname): """Pool child process initializer.""" platforms.signals.reset(*WORKER_SIGRESET) platforms.signals.ignore(*WORKER_SIGIGNORE) platforms.set_mp_process_title('celeryd', hostname=hostname) # This is for Windows and other platforms not supporting # fork(). Note that init_worker makes sure it's only # run once per process. app.loader.init_worker() app.loader.init_worker_process() app.log.setup(int(os.environ.get('CELERY_LOG_LEVEL', 0)), os.environ.get('CELERY_LOG_FILE') or None, bool(os.environ.get('CELERY_LOG_REDIRECT', False)), str(os.environ.get('CELERY_LOG_REDIRECT_LEVEL'))) if os.environ.get('FORKED_BY_MULTIPROCESSING'): # pool did execv after fork trace.setup_worker_optimizations(app) else: app.set_current() set_default_app(app) app.finalize() trace._tasks = app._tasks # enables fast_trace_task optimization. from celery.task.trace import build_tracer for name, task in items(app.tasks): task.__trace__ = build_tracer(name, task, app.loader, hostname) signals.worker_process_init.send(sender=None)
def update_strategies(self): S = self.strategies app = self.app loader = app.loader hostname = self.hostname for name, task in self.app.tasks.iteritems(): S[name] = task.start_strategy(app, self) task.__trace__ = build_tracer(name, task, loader, hostname)
def test_fast_trace_task(self): from celery.task import trace setup_worker_optimizations(self.app) self.assertIs(trace.trace_task_ret, trace._fast_trace_task) try: mytask.__trace__ = build_tracer(mytask.name, mytask, self.app.loader, 'test') res = trace.trace_task_ret(mytask.name, uuid(), [4], {}) self.assertEqual(res, 4 ** 4) finally: reset_worker_optimizations() self.assertIs(trace.trace_task_ret, trace._trace_task_ret) delattr(mytask, '__trace__') res = trace.trace_task_ret(mytask.name, uuid(), [4], {}) self.assertEqual(res, 4 ** 4)
def execute_and_trace(name, uuid, args, kwargs, request=None, **opts): """This is a pickleable method used as a target when applying to pools. It's the same as:: >>> trace_task(name, *args, **kwargs)[0] """ task = _tls.current_app._tasks[name] try: hostname = opts.get("hostname") setps("celeryd", name, hostname, rate_limit=True) try: if task.__tracer__ is None: task.__tracer__ = build_tracer(name, task, **opts) return task.__tracer__(uuid, args, kwargs, request)[0] finally: setps("celeryd", "-idle-", hostname, rate_limit=True) except Exception, exc: return report_internal_error(task, exc)
def execute_and_trace(name, uuid, args, kwargs, request=None, **opts): """This is a pickleable method used as a target when applying to pools. It's the same as:: >>> trace_task(name, *args, **kwargs)[0] """ task = current_app.tasks[name] try: hostname = opts.get("hostname") setps("celeryd", name, hostname, rate_limit=True) try: if task.__tracer__ is None: task.__tracer__ = build_tracer(name, task, **opts) return task.__tracer__(uuid, args, kwargs, request)[0] finally: setps("celeryd", "-idle-", hostname, rate_limit=True) except Exception, exc: return report_internal_error(task, exc)
def process_initializer(app, hostname): """Initializes the process so it can be used to process tasks.""" app = app_or_default(app) app.set_current() platforms.signals.reset(*WORKER_SIGRESET) platforms.signals.ignore(*WORKER_SIGIGNORE) platforms.set_mp_process_title("celeryd", hostname=hostname) # This is for Windows and other platforms not supporting # fork(). Note that init_worker makes sure it's only # run once per process. app.log.setup(int(os.environ.get("CELERY_LOG_LEVEL", 0)), os.environ.get("CELERY_LOG_FILE") or None, bool(os.environ.get("CELERY_LOG_REDIRECT", False)), str(os.environ.get("CELERY_LOG_REDIRECT_LEVEL"))) app.loader.init_worker() app.loader.init_worker_process() app.finalize() from celery.task.trace import build_tracer for name, task in app.tasks.iteritems(): task.__tracer__ = build_tracer(name, task, app.loader, hostname) signals.worker_process_init.send(sender=None)
def process_initializer(app, hostname): """Initializes the process so it can be used to process tasks.""" app.set_current() set_default_app(app) trace._tasks = app._tasks # make sure this optimization is set. platforms.signals.reset(*WORKER_SIGRESET) platforms.signals.ignore(*WORKER_SIGIGNORE) platforms.set_mp_process_title('celeryd', hostname=hostname) # This is for Windows and other platforms not supporting # fork(). Note that init_worker makes sure it's only # run once per process. app.log.setup(int(os.environ.get('CELERY_LOG_LEVEL', 0)), os.environ.get('CELERY_LOG_FILE') or None, bool(os.environ.get('CELERY_LOG_REDIRECT', False)), str(os.environ.get('CELERY_LOG_REDIRECT_LEVEL'))) app.loader.init_worker() app.loader.init_worker_process() app.finalize() from celery.task.trace import build_tracer for name, task in app.tasks.iteritems(): task.__trace__ = build_tracer(name, task, app.loader, hostname) signals.worker_process_init.send(sender=None)
def update_strategies(self): loader = self.app.loader for name, task in items(self.app.tasks): self.strategies[name] = task.start_strategy(self.app, self) task.__trace__ = build_tracer(name, task, loader, self.hostname)
def test_trace_task_ret(self): mytask.__trace__ = build_tracer(mytask.name, mytask, self.app.loader, 'test') res = _trace_task_ret(mytask.name, uuid(), [4], {}) self.assertEqual(res, 4 ** 4)
def test_trace_task_ret(self): mytask.__trace__ = build_tracer(mytask.name, mytask, current_app.loader, "test") res = trace_task_ret(mytask.name, uuid(), [4], {}) self.assertEqual(res, 4**4)
def test_trace_task_ret(self): mytask.__trace__ = build_tracer(mytask.name, mytask, current_app.loader, "test") res = trace_task_ret(mytask.name, uuid(), [4], {}) self.assertEqual(res, 4 ** 4)