This document describes the current stable version of Celery (5.6). For development docs, go here.

# `celery.worker.worker`

WorkController can be used to instantiate in-process workers.

The command-line interface for the worker is in `celery.bin.worker`, while the worker program is in `celery.apps.worker`.

The worker program is responsible for adding signal handlers, setting up logging, etc. This is a bare-bones worker without global side-effects (i.e., except for the global state stored in `celery.worker.state`).

The worker consists of several components, all managed by bootsteps (mod:celery.bootsteps).

class celery.worker.worker.WorkController(app=None, hostname=None, **kwargs)

  Unmanaged worker instance.

  class Blueprint(steps=None, name=None, on_start=None, on_close=None, on_stopped=None)

    Worker bootstep blueprint.

    default_steps = {'celery.worker.autoscale:WorkerComponent', 'celery.worker.components:Beat', 'celery.worker.components:Consumer', 'celery.worker.components:Hub', 'celery.worker.components:Pool', 'celery.worker.components:StateDB', 'celery.worker.components:Timer'}
    name = 'Worker'
  app = None
  blueprint = None
  exitcode = None

    contains the exit code if a `SystemExit` event is handled.

  info()
  on_after_init(**kwargs)
  on_before_init(**kwargs)
  on_close()
  on_consumer_ready(consumer)
  on_init_blueprint()
  on_start()
  on_stopped()
  pidlock = None
  pool = None
  prepare_args(**kwargs)
  register_with_event_loop(hub)
  reload(modules=None, reload=False, reloader=None)
  rusage()
  semaphore = None
  setup_defaults(concurrency=None, loglevel='WARN', logfile=None, task_events=None, pool=None, consumer_cls=None, timer_cls=None, timer_precision=None, autoscaler_cls=None, pool_putlocks=None, pool_restarts=None, optimization=None, O=None, statedb=None, time_limit=None, soft_time_limit=None, scheduler=None, pool_cls=None, state_db=None, task_time_limit=None, task_soft_time_limit=None, scheduler_cls=None, schedule_filename=None, max_tasks_per_child=None, prefetch_multiplier=None, disable_rate_limits=None, worker_lost_wait=None, max_memory_per_child=None, **_kw)
  setup_includes(includes)
  setup_instance(queues=None, ready_callback=None, pidfile=None, include=None, use_eventloop=None, exclude_queues=None, **kwargs)
  setup_queues(include, exclude=None)
  should_use_eventloop()
  signal_consumer_close()
  start()
  property state
  stats()
  stop(in_sighandler=False, exitcode=None)

    Graceful shutdown of the worker server (Warm shutdown).

  terminate(in_sighandler=False)

    Not so graceful shutdown of the worker server (Cold shutdown).

  wait_for_soft_shutdown()

    Wait `worker_soft_shutdown_timeout` if soft shutdown is enabled.

    To enable soft shutdown, set the `worker_soft_shutdown_timeout` in the configuration. Soft shutdown can be used to allow the worker to finish processing few more tasks before initiating a cold shutdown. This mechanism allows the worker to finish short tasks that are already in progress and requeue long-running tasks to be picked up by another worker.

    Warning

    If there are no tasks in the worker, the worker will not wait for the soft shutdown timeout even if it is set as it makes no sense to wait for the timeout when there are no tasks to process.