Closed cenkalti closed 10 years ago
Hello @gmr. Did you have a chance to take a look?
This PR fixes #38.
I've not, sorry juggling quite a few things. I'll pull it down shortly and see where it leads :)
In testing, this breaks consumer behavior to no longer be blocking with a context manager. Looking to see if I can identify why.
@gmr I have fixed the blocking consumer problem.
Ok, I'll review in the next day or two. I'm a bit hesitant to make API changes, but may be able to take what you wrote and massage it a bit to get it where it needs to be.
Great, I have squashed my commits into one for more clean history. Thanks!
This is how I use it:
def run(self):
with self.queue.consumer() as consumer:
self.consumer = consumer
for message in consumer.next_message():
self.process_message(message)
def handle_sigterm(self, signum, frame):
self.warm_shutdown()
def warm_shutdown(self):
"""Exit after the last task is finished."""
if self.consumer:
self.consumer.cancel()
Hey Cenk,
I really appreciate your pull-request and effort. I decided to implement this in a slightly different way that didn't require as many structural changes. I'm going to close out this PR and we can continue the discussion in #38
Hello @gmr I have added
Consumer.cancel()
method and have done some refactoring. I believe that I did not make any changes that breaks backward compatibility. In order to cancel a consumingConsumer
I had to inject a new object (base.InternalCommand
) into the channel's read queue when aBasic.CancelOk
frame is received. It does not support cancellation of multiple concurrent consumers yet becauseCancelConsumer
objects do not have any identifier for consumers (consumer_tag
). However, it works perfectly for a single consumer. If you want a change about this, I can modify my pull request.