txamqp-user team mailing list archive
-
txamqp-user team
-
Mailing list archive
-
Message #00046
Re: How do you listen to different queues asynchronously?
Hi Terry
On Mon, Nov 16, 2009 at 1:26 AM, Terry Jones <terry@xxxxxxxxxxxxx> wrote:
> @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.
there's probably something I'm missing here, but why are you defining
a function and attaching it to an errback if you're already using
inlineCallbacks? This looks cleaner to me:
@inlineCallbacks
def consumer_fanout(conn, chan, queue, sig):
done = False
while not done:
try:
msg = yield queue.get()
print '[FANOUT] Received: ' + msg.content.body + ...
except: # you may replace this with except SomeErrorType
done = True
yield chan.basic_cancel("testtag_fanout")
Cheers.
Follow ups
References