本文整理汇总了Python中celery.worker.WorkController类的典型用法代码示例。如果您正苦于以下问题:Python WorkController类的具体用法?Python WorkController怎么用?Python WorkController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WorkController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_start
def on_start(self):
WorkController.on_start(self)
# apply task execution optimizations
trace.setup_worker_optimizations(self.app)
# this signal can be used to e.g. change queues after
# the -Q option has been applied.
signals.celeryd_after_setup.send(
sender=self.hostname, instance=self, conf=self.app.conf,
)
if getattr(os, 'getuid', None) and os.getuid() == 0:
warnings.warn(RuntimeWarning(
'Running celeryd with superuser privileges is discouraged!'))
if self.purge:
self.purge_messages()
# Dump configuration to screen so we have some basic information
# for when users sends bug reports.
print(str(self.colored.cyan(' \n', self.startup_info())) +
str(self.colored.reset(self.extra_info() or '')))
self.set_process_status('-active-')
self.setup_logging()
self.install_platform_tweaks(self)
示例2: on_start
def on_start(self):
app = self.app
WorkController.on_start(self)
# this signal can be used to e.g. change queues after
# the -Q option has been applied.
signals.celeryd_after_setup.send(
sender=self.hostname, instance=self, conf=app.conf,
)
if self.purge:
self.purge_messages()
# Dump configuration to screen so we have some basic information
# for when users sends bug reports.
use_image = self._term_supports_images()
if use_image:
self.termimage(static.logo_as_base64())
print(safe_str(''.join([
string(self.colored.cyan(
' \n', self.startup_info(artlines=not use_image))),
string(self.colored.reset(self.extra_info() or '')),
])), file=sys.__stdout__)
self.set_process_status('-active-')
self.install_platform_tweaks(self)
if not self._custom_logging and self.redirect_stdouts:
app.log.redirect_stdouts(self.redirect_stdouts_level)
示例3: on_start
def on_start(self):
if not self._custom_logging and self.redirect_stdouts:
self.app.log.redirect_stdouts(self.redirect_stdouts_level)
WorkController.on_start(self)
# this signal can be used to e.g. change queues after
# the -Q option has been applied.
signals.celeryd_after_setup.send(sender=self.hostname, instance=self, conf=self.app.conf)
if not self.app.conf.value_set_for("accept_content"):
warnings.warn(CDeprecationWarning(W_PICKLE_DEPRECATED))
if self.purge:
self.purge_messages()
# Dump configuration to screen so we have some basic information
# for when users sends bug reports.
print(
safe_str(
"".join(
[
string(self.colored.cyan(" \n", self.startup_info())),
string(self.colored.reset(self.extra_info() or "")),
]
)
),
file=sys.__stdout__,
)
self.set_process_status("-active-")
self.install_platform_tweaks(self)
示例4: bench_consumer
def bench_consumer(n=10000):
from celery.worker import WorkController
from celery.worker import state
worker = WorkController(app=celery, pool_cls="solo")
time_start = [None]
@celery.task()
def it(i):
if not i:
time_start[0] = time.time()
elif i == n - 1:
print(time.time() - time_start[0])
@celery.task()
def shutdown_worker():
raise SystemExit()
for i in xrange(n):
it.delay(i)
shutdown_worker.delay()
try:
worker.start()
except SystemExit:
assert sum(state.total_count.values()) == n + 1
示例5: on_start
def on_start(self):
if not self._custom_logging and self.redirect_stdouts:
self.app.log.redirect_stdouts(self.redirect_stdouts_level)
WorkController.on_start(self)
# this signal can be used to e.g. change queues after
# the -Q option has been applied.
signals.celeryd_after_setup.send(
sender=self.hostname, instance=self, conf=self.app.conf,
)
if getattr(os, 'getuid', None) and os.getuid() == 0:
accept_encoding = self.app.conf.CELERY_ACCEPT_CONTENT
if ('pickle' in accept_encoding or
'application/x-python-serialize' in accept_encoding):
if not C_FORCE_ROOT:
raise RuntimeError(ROOT_DISALLOWED)
warnings.warn(RuntimeWarning(ROOT_DISCOURAGED))
if self.purge:
self.purge_messages()
# Dump configuration to screen so we have some basic information
# for when users sends bug reports.
sys.__stdout__.write(
str(self.colored.cyan(' \n', self.startup_info())) +
str(self.colored.reset(self.extra_info() or '')) + '\n'
)
self.set_process_status('-active-')
self.install_platform_tweaks(self)
示例6: on_start
def on_start(self):
if not self._custom_logging and self.redirect_stdouts:
self.app.log.redirect_stdouts(self.redirect_stdouts_level)
WorkController.on_start(self)
# this signal can be used to e.g. change queues after
# the -Q option has been applied.
signals.celeryd_after_setup.send(
sender=self.hostname, instance=self, conf=self.app.conf,
)
if getattr(os, 'getuid', None) and os.getuid() == 0:
warnings.warn(RuntimeWarning(
'Running the worker with superuser privileges is discouraged!',
))
if self.purge:
self.purge_messages()
# Dump configuration to screen so we have some basic information
# for when users sends bug reports.
sys.__stdout__.write(
str(self.colored.cyan(' \n', self.startup_info())) +
str(self.colored.reset(self.extra_info() or '')) + '\n'
)
self.set_process_status('-active-')
self.install_platform_tweaks(self)
示例7: test_on_timer_tick
def test_on_timer_tick(self):
worker = WorkController(concurrency=1, loglevel=10)
worker.logger = Mock()
worker.timer_debug = worker.logger.debug
worker.on_timer_tick(30.0)
logged = worker.logger.debug.call_args[0][0]
self.assertIn("30.0", logged)
示例8: test_on_timer_tick
def test_on_timer_tick(self):
worker = WorkController(concurrency=1, loglevel=10)
worker.logger = Mock()
worker.on_timer_tick(30.0)
xargs = worker.logger.debug.call_args[0]
fmt, arg = xargs[0], xargs[1]
self.assertEqual(30.0, arg)
self.assertIn("Next eta %s secs", fmt)
示例9: run_worker
def run_worker():
worker = WorkController(concurrency=concurrency,
loglevel=loglevel,
logfile=logfile,
is_detached=detach)
try:
worker.start()
except Exception, e:
emergency_error(logfile, "celeryd raised exception %s: %s\n%s" % (
e.__class__, e, traceback.format_exc()))
示例10: test_on_timer_error
def test_on_timer_error(self):
worker = WorkController(concurrency=1, loglevel=0)
worker.logger = Mock()
try:
raise KeyError("foo")
except KeyError:
exc_info = sys.exc_info()
worker.on_timer_error(exc_info)
msg, args = worker.logger.error.call_args[0]
self.assertIn("KeyError", msg % args)
示例11: test_on_timer_error
def test_on_timer_error(self):
worker = WorkController(concurrency=1, loglevel=0)
worker.logger = MockLogger()
try:
raise KeyError("foo")
except KeyError:
exc_info = sys.exc_info()
worker.on_timer_error(exc_info)
logged = worker.logger.logged[0]
self.assertIn("KeyError", logged)
示例12: run_worker
def run_worker():
worker = WorkController(concurrency=concurrency,
loglevel=loglevel,
logfile=logfile,
is_detached=detach)
# Install signal handler that restarts celeryd on SIGHUP
install_restart_signal_handler(worker)
try:
worker.start()
except Exception, e:
emergency_error(logfile, "celeryd raised exception %s: %s\n%s" % (
e.__class__, e, traceback.format_exc()))
示例13: test_dont_stop_or_terminate
def test_dont_stop_or_terminate(self):
worker = WorkController(concurrency=1, loglevel=0)
worker.stop()
self.assertNotEqual(worker._state, worker.CLOSE)
worker.terminate()
self.assertNotEqual(worker._state, worker.CLOSE)
sigsafe, worker.pool.signal_safe = worker.pool.signal_safe, False
try:
worker._state = worker.RUN
worker.stop(in_sighandler=True)
self.assertNotEqual(worker._state, worker.CLOSE)
worker.terminate(in_sighandler=True)
self.assertNotEqual(worker._state, worker.CLOSE)
finally:
worker.pool.signal_safe = sigsafe
示例14: run_worker
def run_worker():
worker = WorkController(concurrency=concurrency,
loglevel=loglevel,
logfile=logfile,
hostname=hostname,
embed_clockservice=run_clockservice,
send_events=events)
# Install signal handler so SIGHUP restarts the worker.
install_worker_restart_handler(worker)
from celery import signals
signals.worker_init.send(sender=worker)
try:
worker.start()
except Exception, e:
emergency_error(logfile, "celeryd raised exception %s: %s\n%s" % (
e.__class__, e, traceback.format_exc()))
示例15: on_start
def on_start(self):
app = self.app
WorkController.on_start(self)
# this signal can be used to, for example, change queues after
# the -Q option has been applied.
signals.celeryd_after_setup.send(
sender=self.hostname, instance=self, conf=app.conf,
)
if self.purge:
self.purge_messages()
if not self.quiet:
self.emit_banner()
self.set_process_status('-active-')
self.install_platform_tweaks(self)
if not self._custom_logging and self.redirect_stdouts:
app.log.redirect_stdouts(self.redirect_stdouts_level)