當前位置: 首頁>>代碼示例>>Python>>正文


Python LightQueue.put方法代碼示例

本文整理匯總了Python中eventlet.queue.LightQueue.put方法的典型用法代碼示例。如果您正苦於以下問題:Python LightQueue.put方法的具體用法?Python LightQueue.put怎麽用?Python LightQueue.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在eventlet.queue.LightQueue的用法示例。


在下文中一共展示了LightQueue.put方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ProducerPool

# 需要導入模塊: from eventlet.queue import LightQueue [as 別名]
# 或者: from eventlet.queue.LightQueue import put [as 別名]
class ProducerPool(object):
    Receipt = Receipt

    def __init__(self, size=20):
        self.size = size
        self.inqueue = LightQueue()
        self._running = None
        self._producers = None

    def apply_async(self, task, args, kwargs, callback=None, **options):
        if self._running is None:
            self._running = spawn_n(self._run)
        receipt = self.Receipt(callback)
        self.inqueue.put((task, args, kwargs, options, receipt))
        return receipt

    def _run(self):
        self._producers = [spawn_n(self._producer)
                                for _ in xrange(self.size)]

    def _producer(self):
        connection = current_app.broker_connection()
        publisher = current_app.amqp.TaskPublisher(connection)
        inqueue = self.inqueue

        while 1:
            task, args, kwargs, options, receipt = inqueue.get()
            result = task.apply_async(args, kwargs,
                                      publisher=publisher,
                                      **options)
            receipt.finished(result)
開發者ID:Aaron1011,項目名稱:oh-mainline,代碼行數:33,代碼來源:bulk_task_producer.py

示例2: ProducerPool

# 需要導入模塊: from eventlet.queue import LightQueue [as 別名]
# 或者: from eventlet.queue.LightQueue import put [as 別名]
class ProducerPool(object):
    """Usage::

        >>> app = Celery(broker='amqp://')
        >>> ProducerPool(app)

    """
    Receipt = Receipt

    def __init__(self, app, size=20):
        self.app = app
        self.size = size
        self.inqueue = LightQueue()
        self._running = None
        self._producers = None

    def apply_async(self, task, args, kwargs, callback=None, **options):
        if self._running is None:
            self._running = spawn_n(self._run)
        receipt = self.Receipt(callback)
        self.inqueue.put((task, args, kwargs, options, receipt))
        return receipt

    def _run(self):
        self._producers = [spawn_n(self._producer) for _ in range(self.size)]

    def _producer(self):
        inqueue = self.inqueue

        with self.app.producer_or_acquire() as producer:
            while 1:
                task, args, kwargs, options, receipt = inqueue.get()
                result = task.apply_async(
                    args, kwargs, producer=producer, **options)
                receipt.finished(result)
開發者ID:prmtl,項目名稱:celery,代碼行數:37,代碼來源:bulk_task_producer.py

示例3: get

# 需要導入模塊: from eventlet.queue import LightQueue [as 別名]
# 或者: from eventlet.queue.LightQueue import put [as 別名]
 def get(self, timeout=10):  # pylint: disable=missing-docstring
     name = getter.__name__
     signal = '{uuid}{sep}{event}'.format(
         uuid=self._uuid,  # pylint: disable=protected-access
         sep=SEPARATOR,
         event=name
     )
     event = LightQueue(1)
     if flask.has_request_context():
         emit(signal, callback=lambda x: event.put(unpack(x)))
     else:
         sio = flask.current_app.extensions['socketio']
         sio.emit(signal, callback=lambda x: event.put(unpack(x)))
     data = event.get(timeout=timeout)
     return getter(self, data)
開發者ID:jwkvam,項目名稱:bowtie,代碼行數:17,代碼來源:_component.py

示例4: LocalMailbox

# 需要導入模塊: from eventlet.queue import LightQueue [as 別名]
# 或者: from eventlet.queue.LightQueue import put [as 別名]
class LocalMailbox(Mailbox):
    __slots__ = ['_queue']

    def __init__(self):
        self._queue = LightQueue()

    def put(self, message):
        self._queue.put(message)

    def get(self):
        return self._queue.get(block=True)

    def encode(self):
        raise NotImplementedError

    @staticmethod
    def decode(params):
        raise NotImplementedError
開發者ID:i2y,項目名稱:mochi,代碼行數:20,代碼來源:mailbox.py


注:本文中的eventlet.queue.LightQueue.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。