Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consumer.iterconsume should raise StopIteration when backend channel is closed #24

Closed
stevvooe opened this issue Feb 26, 2010 · 0 comments

Comments

@stevvooe
Copy link
Contributor

A colleague of mine noticed that I had these peppered through some consumer daemons:
for m in self.iterconsume():
if self.closed:
break

To handle signals for a graceful daemon close, we close the channel asynchronously. Which will cause an exception in the iterconsume or when it tries to fetch the next message. I put the flag there to prevent some wild exception from bleeding through. As a test, we modified the pyamqplib backend to raise a StopIteration when the channel is closed (sorry for the lack of a diff):
def consume(self, limit=None):
"""Returns an iterator that waits for one message at a time."""
for total_message_count in count():
if limit and total_message_count >= limit:
raise StopIteration

        if not self.channel.is_open:
            raise StopIteration

        self.channel.wait()
        yield True

There is also the case where an amqp exception can be raised by the channel.wait call, but I defer the handling of that up to you (catch AMQPException and raise StopIteration or let the Exception bleed through; I am for the latter).

Let me know if you need any other information on this.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant