当前位置: 首页>>代码示例>>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;未经允许,请勿转载。