本文整理汇总了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)
示例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)
示例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)
示例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