|
@@ -9,6 +9,7 @@
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
import os
|
|
|
+import sys
|
|
|
import threading
|
|
|
import warnings
|
|
|
|
|
@@ -37,7 +38,7 @@ from celery.local import PromiseProxy, maybe_evaluate
|
|
|
from celery.utils.dispatch import Signal
|
|
|
from celery.utils.functional import first, maybe_list
|
|
|
from celery.utils.imports import instantiate, symbol_by_name
|
|
|
-from celery.utils.objects import mro_lookup
|
|
|
+from celery.utils.objects import FallbackContext, mro_lookup
|
|
|
|
|
|
from .annotations import prepare as prepare_annotations
|
|
|
from .defaults import DEFAULTS, find_deprecated_settings
|
|
@@ -411,27 +412,20 @@ class Celery(object):
|
|
|
)
|
|
|
broker_connection = connection
|
|
|
|
|
|
- @contextmanager
|
|
|
- def connection_or_acquire(self, connection=None, pool=True,
|
|
|
- *args, **kwargs):
|
|
|
- if connection:
|
|
|
- yield connection
|
|
|
- else:
|
|
|
- if pool:
|
|
|
- with self.pool.acquire(block=True) as connection:
|
|
|
- yield connection
|
|
|
- else:
|
|
|
- with self.connection() as connection:
|
|
|
- yield connection
|
|
|
+ def _acquire_connection(self, pool=True):
|
|
|
+ """Helper for :meth:`connection_or_acquire`."""
|
|
|
+ if pool:
|
|
|
+ return self.pool.acquire(block=True)
|
|
|
+ return self.connection()
|
|
|
+
|
|
|
+ def connection_or_acquire(self, connection=None, pool=True, *_, **__):
|
|
|
+ return FallbackContext(connection, self._acquire_connection, pool=pool)
|
|
|
default_connection = connection_or_acquire # XXX compat
|
|
|
|
|
|
- @contextmanager
|
|
|
def producer_or_acquire(self, producer=None):
|
|
|
- if producer:
|
|
|
- yield producer
|
|
|
- else:
|
|
|
- with self.amqp.producer_pool.acquire(block=True) as producer:
|
|
|
- yield producer
|
|
|
+ return FallbackContext(
|
|
|
+ producer, self.amqp.producer_pool.acquire, block=True,
|
|
|
+ )
|
|
|
default_producer = producer_or_acquire # XXX compat
|
|
|
|
|
|
def prepare_config(self, c):
|