txamqp-user team mailing list archive
-
txamqp-user team
-
Mailing list archive
-
Message #00043
Re: How do you listen to different queues asynchronously?
> I was looking for a way to stop the:
>
> while True:
> msg = yield queue.get()
>
> What should I do if the loop is just stuck in yield queue.get() and I
> want to cancel it?
>
> My program is a GTK2 app that keeps listening to messages and I would
> like to stop listening when I close the app. So I "invented" that. The
> trouble with it is that queue.get() throws Closed so I have to add an
> errback to trap it.
I'm not 100% sure I understand what you want or what your situation is, but
maybe something like this is what you want:
@inlineCallbacks
def consumer_fanout(conn, chan, queue, sig):
done = False
def _cancel(failure):
# failure.trap(SomeErrorType)
done = True
return chan.basic_cancel("testtag_fanout")
while not done:
d = queue.get()
d.addErrback(_cancel)
msg = yield d
print '[FANOUT] Received: ' + msg.content.body + ...
And you might want to use failure.trap in _cancel to make sure you have a
Closed error, supposing you care.
Terry
Follow ups
References