本文整理汇总了Python中celery.worker.listener.CarrotListener.close_connection方法的典型用法代码示例。如果您正苦于以下问题:Python CarrotListener.close_connection方法的具体用法?Python CarrotListener.close_connection怎么用?Python CarrotListener.close_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.worker.listener.CarrotListener
的用法示例。
在下文中一共展示了CarrotListener.close_connection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_close_connection
# 需要导入模块: from celery.worker.listener import CarrotListener [as 别名]
# 或者: from celery.worker.listener.CarrotListener import close_connection [as 别名]
def test_close_connection(self):
l = CarrotListener(self.ready_queue, self.eta_schedule, self.logger,
send_events=False)
l._state = RUN
l.close_connection()
l = CarrotListener(self.ready_queue, self.eta_schedule, self.logger,
send_events=False)
eventer = l.event_dispatcher = MockEventDispatcher()
heart = l.heart = MockHeart()
l._state = RUN
l.stop_consumers()
self.assertTrue(eventer.closed)
self.assertTrue(heart.closed)
示例2: test_connection
# 需要导入模块: from celery.worker.listener import CarrotListener [as 别名]
# 或者: from celery.worker.listener.CarrotListener import close_connection [as 别名]
def test_connection(self):
l = CarrotListener(self.ready_queue, self.eta_schedule, self.logger,
send_events=False)
l.reset_connection()
self.assertTrue(isinstance(l.connection, BrokerConnection))
l.close_connection()
self.assertTrue(l.connection is None)
self.assertTrue(l.task_consumer is None)
l.reset_connection()
self.assertTrue(isinstance(l.connection, BrokerConnection))
l.stop()
self.assertTrue(l.connection is None)
self.assertTrue(l.task_consumer is None)
示例3: WorkController
# 需要导入模块: from celery.worker.listener import CarrotListener [as 别名]
# 或者: from celery.worker.listener.CarrotListener import close_connection [as 别名]
#.........这里部分代码省略.........
self.hostname = hostname or socket.gethostname()
self.embed_clockservice = embed_clockservice
self.ready_callback = ready_callback
self.send_events = send_events
self._finalize = Finalize(self, self.stop, exitpriority=20)
# Queues
if conf.DISABLE_RATE_LIMITS:
self.ready_queue = Queue()
else:
self.ready_queue = TaskBucket(task_registry=registry.tasks)
self.eta_schedule = Scheduler(self.ready_queue)
self.logger.debug("Instantiating thread components...")
# Threads + Pool + Consumer
self.pool = TaskPool(self.concurrency,
logger=self.logger,
initializer=process_initializer)
self.mediator = Mediator(self.ready_queue,
callback=self.process_task,
logger=self.logger)
self.scheduler = ScheduleController(self.eta_schedule,
logger=self.logger)
self.clockservice = None
if self.embed_clockservice:
self.clockservice = EmbeddedClockService(logger=self.logger,
schedule_filename=schedule_filename)
prefetch_count = self.concurrency * conf.CELERYD_PREFETCH_MULTIPLIER
self.listener = CarrotListener(self.ready_queue,
self.eta_schedule,
logger=self.logger,
hostname=self.hostname,
send_events=self.send_events,
init_callback=self.ready_callback,
initial_prefetch_count=prefetch_count)
# The order is important here;
# the first in the list is the first to start,
# and they must be stopped in reverse order.
self.components = filter(None, (self.pool,
self.mediator,
self.scheduler,
self.clockservice,
self.listener))
def start(self):
"""Starts the workers main loop."""
self._state = "RUN"
try:
for component in self.components:
self.logger.debug("Starting thread %s..." % \
component.__class__.__name__)
component.start()
finally:
self.stop()
def process_task(self, wrapper):
"""Process task by sending it to the pool of workers."""
try:
try:
wrapper.task.execute(wrapper, self.pool,
self.loglevel, self.logfile)
except Exception, exc:
self.logger.critical("Internal error %s: %s\n%s" % (
exc.__class__, exc, traceback.format_exc()))
except (SystemExit, KeyboardInterrupt):
self.stop()
def stop(self):
"""Gracefully shutdown the worker server."""
if self._state != "RUN":
return
signals.worker_shutdown.send(sender=self)
for component in reversed(self.components):
self.logger.debug("Stopping thread %s..." % (
component.__class__.__name__))
component.stop()
self.listener.close_connection()
self._state = "STOP"
def terminate(self):
"""Not so gracefully shutdown the worker server."""
if self._state != "RUN":
return
signals.worker_shutdown.send(sender=self)
for component in reversed(self.components):
self.logger.debug("Terminating thread %s..." % (
component.__class__.__name__))
terminate = getattr(component, "terminate", component.stop)
terminate()
self.listener.close_connection()
self._state = "STOP"