Closed cenkalti closed 9 years ago
This is not the right way to address the issue. I've added a new test that demonstrates that you can stop consuming outside of the thread. I don't see an issue here.
class PublishAndConsumeIteratorStopTest(unittest.TestCase):
def setUp(self):
self.connection = rabbitpy.Connection()
self.channel = self.connection.channel()
self.exchange = rabbitpy.TopicExchange(self.channel, 'test-pacit')
self.exchange.declare()
self.queue = rabbitpy.Queue(self.channel, 'pacit-queue')
self.queue.declare()
self.queue.bind(self.exchange, 'test.#')
self.app_id = 'PublishAndConsumeIteratorTest'
self.message_body = 'ABC1234567890'
self.message_type = 'test'
for iteration in range(0, 10):
self.msg = rabbitpy.Message(self.channel,
self.message_body,
{'app_id': self.app_id,
'message_id': str(uuid.uuid4()),
'timestamp': int(time.time()),
'message_type': self.message_type})
self.msg.publish(self.exchange,
'test.publish.consume {0}'.format(iteration))
def stop_consumer(self):
self.queue.stop_consuming()
def tearDown(self):
self.queue.delete()
self.exchange.delete()
def test_iterator_exits_on_stop(self):
LOGGER.info('Starting stop timer')
timer = threading.Timer(2, self.stop_consumer)
timer.daemon = True
timer.start()
for msg in self.queue:
if not msg:
LOGGER.info('Message is empty')
break
msg.ack()
LOGGER.info('Exited iterator')
self.assertFalse(self.queue.consuming)
Fixes the issue that I mention at: https://github.com/cenkalti/rabbitpy/commit/ea6a33e982c912db5815653833a77e1e71452ada#commitcomment-8033548