本文整理汇总了Python中celery.five.Queue.get_nowait方法的典型用法代码示例。如果您正苦于以下问题:Python Queue.get_nowait方法的具体用法?Python Queue.get_nowait怎么用?Python Queue.get_nowait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.five.Queue
的用法示例。
在下文中一共展示了Queue.get_nowait方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_Consumer
# 需要导入模块: from celery.five import Queue [as 别名]
# 或者: from celery.five.Queue import get_nowait [as 别名]
#.........这里部分代码省略.........
content_encoding = 'binary'
body = 'foobarbaz'
message = MockMessage()
c.on_decode_error(message, KeyError('foo'))
assert message.ack.call_count
assert "Can't decode message body" in crit.call_args[0][0]
def _get_on_message(self, c):
if c.qos is None:
c.qos = Mock()
c.task_consumer = Mock()
c.event_dispatcher = mock_event_dispatcher()
c.connection = Mock(name='.connection')
c.connection.get_heartbeat_interval.return_value = 0
c.connection.drain_events.side_effect = WorkerShutdown()
with pytest.raises(WorkerShutdown):
c.loop(*c.loop_args())
assert c.task_consumer.on_message
return c.task_consumer.on_message
def test_receieve_message(self):
c = self.LoopConsumer()
c.blueprint.state = RUN
m = self.create_task_message(
Mock(), self.foo_task.name,
args=[2, 4, 8], kwargs={},
)
c.update_strategies()
callback = self._get_on_message(c)
callback(m)
in_bucket = self.buffer.get_nowait()
assert isinstance(in_bucket, Request)
assert in_bucket.name == self.foo_task.name
assert in_bucket.execute() == 2 * 4 * 8
assert self.timer.empty()
def test_start_channel_error(self):
c = self.NoopConsumer(task_events=False, pool=BasePool())
c.loop.on_nth_call_do_raise(KeyError('foo'), SyntaxError('bar'))
c.channel_errors = (KeyError,)
try:
with pytest.raises(KeyError):
c.start()
finally:
c.timer and c.timer.stop()
def test_start_connection_error(self):
c = self.NoopConsumer(task_events=False, pool=BasePool())
c.loop.on_nth_call_do_raise(KeyError('foo'), SyntaxError('bar'))
c.connection_errors = (KeyError,)
try:
with pytest.raises(SyntaxError):
c.start()
finally:
c.timer and c.timer.stop()
def test_loop_ignores_socket_timeout(self):
class Connection(self.app.connection_for_read().__class__):
obj = None
def drain_events(self, **kwargs):
self.obj.connection = None
示例2: test_Consumer
# 需要导入模块: from celery.five import Queue [as 别名]
# 或者: from celery.five.Queue import get_nowait [as 别名]
#.........这里部分代码省略.........
class MockMessage(Mock):
content_type = 'application/x-msgpack'
content_encoding = 'binary'
body = 'foobarbaz'
message = MockMessage()
l.on_decode_error(message, KeyError('foo'))
self.assertTrue(message.ack.call_count)
self.assertIn("Can't decode message body", crit.call_args[0][0])
def _get_on_message(self, l):
if l.qos is None:
l.qos = Mock()
l.event_dispatcher = Mock()
l.task_consumer = Mock()
l.connection = Mock()
l.connection.drain_events.side_effect = SystemExit()
with self.assertRaises(SystemExit):
l.loop(*l.loop_args())
self.assertTrue(l.task_consumer.register_callback.called)
return l.task_consumer.register_callback.call_args[0][0]
def test_receieve_message(self):
l = Consumer(self.buffer.put, timer=self.timer, app=self.app)
l.blueprint.state = RUN
l.event_dispatcher = Mock()
m = create_message(Mock(), task=self.foo_task.name,
args=[2, 4, 8], kwargs={})
l.update_strategies()
callback = self._get_on_message(l)
callback(m.decode(), m)
in_bucket = self.buffer.get_nowait()
self.assertIsInstance(in_bucket, Request)
self.assertEqual(in_bucket.name, self.foo_task.name)
self.assertEqual(in_bucket.execute(), 2 * 4 * 8)
self.assertTrue(self.timer.empty())
def test_start_channel_error(self):
class MockConsumer(Consumer):
iterations = 0
def loop(self, *args, **kwargs):
if not self.iterations:
self.iterations = 1
raise KeyError('foo')
raise SyntaxError('bar')
l = MockConsumer(self.buffer.put, timer=self.timer,
send_events=False, pool=BasePool(), app=self.app)
l.channel_errors = (KeyError, )
with self.assertRaises(KeyError):
l.start()
l.timer.stop()
def test_start_connection_error(self):
class MockConsumer(Consumer):
iterations = 0
def loop(self, *args, **kwargs):
if not self.iterations:
self.iterations = 1
raise KeyError('foo')
示例3: test_Consumer
# 需要导入模块: from celery.five import Queue [as 别名]
# 或者: from celery.five.Queue import get_nowait [as 别名]
#.........这里部分代码省略.........
content_type = "application/x-msgpack"
content_encoding = "binary"
body = "foobarbaz"
message = MockMessage()
l.on_decode_error(message, KeyError("foo"))
self.assertTrue(message.ack.call_count)
self.assertIn("Can't decode message body", crit.call_args[0][0])
def _get_on_message(self, l):
if l.qos is None:
l.qos = Mock()
l.event_dispatcher = mock_event_dispatcher()
l.task_consumer = Mock()
l.connection = Mock()
l.connection.drain_events.side_effect = WorkerShutdown()
with self.assertRaises(WorkerShutdown):
l.loop(*l.loop_args())
self.assertTrue(l.task_consumer.on_message)
return l.task_consumer.on_message
def test_receieve_message(self):
l = Consumer(self.buffer.put, timer=self.timer, app=self.app)
l.controller = l.app.WorkController()
l.pool = l.controller.pool = Mock()
l.blueprint.state = RUN
l.event_dispatcher = mock_event_dispatcher()
m = create_task_message(Mock(), self.foo_task.name, args=[2, 4, 8], kwargs={})
l.update_strategies()
callback = self._get_on_message(l)
callback(m)
in_bucket = self.buffer.get_nowait()
self.assertIsInstance(in_bucket, Request)
self.assertEqual(in_bucket.name, self.foo_task.name)
self.assertEqual(in_bucket.execute(), 2 * 4 * 8)
self.assertTrue(self.timer.empty())
def test_start_channel_error(self):
class MockConsumer(Consumer):
iterations = 0
def loop(self, *args, **kwargs):
if not self.iterations:
self.iterations = 1
raise KeyError("foo")
raise SyntaxError("bar")
l = MockConsumer(self.buffer.put, timer=self.timer, send_events=False, pool=BasePool(), app=self.app)
l.controller = l.app.WorkController()
l.pool = l.controller.pool = Mock()
l.channel_errors = (KeyError,)
with self.assertRaises(KeyError):
l.start()
l.timer.stop()
def test_start_connection_error(self):
class MockConsumer(Consumer):
iterations = 0
def loop(self, *args, **kwargs):
if not self.iterations:
self.iterations = 1
raise KeyError("foo")
raise SyntaxError("bar")