"""Pool implementation abstract factory, and alias definitions."""importos# Import from kombu directly as it's used# early in the import stage, where celery.utils loads# too much (e.g., for eventlet patching)fromkombu.utils.importsimportsymbol_by_name__all__=('get_implementation','get_available_pool_names',)ALIASES={'prefork':'celery.concurrency.prefork:TaskPool','eventlet':'celery.concurrency.eventlet:TaskPool','gevent':'celery.concurrency.gevent:TaskPool','solo':'celery.concurrency.solo:TaskPool','processes':'celery.concurrency.prefork:TaskPool',# XXX compat alias}try:importconcurrent.futures# noqaexceptImportError:passelse:ALIASES['threads']='celery.concurrency.thread:TaskPool'## Allow for an out-of-tree worker pool implementation. This is used as follows:## - Set the environment variable CELERY_CUSTOM_WORKER_POOL to the name of# an implementation of :class:`celery.concurrency.base.BasePool` in the# standard Celery format of "package:class".# - Select this pool using '--pool custom'.#try:custom=os.environ.get('CELERY_CUSTOM_WORKER_POOL')exceptKeyError:passelse:ALIASES['custom']=custom
[文档]defget_implementation(cls):"""Return pool implementation by name."""returnsymbol_by_name(cls,ALIASES)
[文档]defget_available_pool_names():"""Return all available pool type names."""returntuple(ALIASES.keys())