Re: [Txamqp-user] How to clean up

2010-06-16 Thread Dave Peticolas

On 06/16/2010 11:56 AM, Andrew Badr wrote:
When a room is created, it should start listening for messages. That's 
why it starts listening in the init, though there is no actual 
processing. Removing the consumer causes the queue to be deleted, so I 
don't think that's necessary.


Here's my current attempt: http://dpaste.com/207704/

What I'm going for here -- not achieved yet -- is to have the same # 
of objects at the 1st and 3rd call to gc.get_objects. My question is 
how to get there. If you look at the unload method, that's my current 
attempt to cleanup, but clearly it's either wrong or there's no right 
way to do it. First time using each of AMQP, Twisted, and the gc 
module, so please tell me what I'm doing wrong. Also, the number of 
extra objects (3rd call - 1st call) increases linearly with the 
argument to range() controlling how many rooms are created, so I know 
it's something relating to room cleanup.


Oh, I see what you mean, I misinterpreted your original message. Looking 
through the code it doesn't look like the TimeoutDeferredQueue

created for a consumer is ever released.


On Mon, Jun 14, 2010 at 7:56 PM, Dave Peticolas > wrote:


On 06/14/2010 05:31 PM, Andrew Badr wrote:

Sorry if you get this message twice; launchpad sucks.

I have a long-running server processes that listen for new
messages from some changing set of rooms. I want to make sure
that when I'm done with a particular room, all the resources
associated with it are eventually freed. Here's what my Room
init code does:

   @inlineCallbacks
   def startListening(self):
   routing_key = 'rooms.' + self.id 


   queue_name = routing_key + '::' + CYCLONE_ID
   AMQP_CHANNEL.queue_declare(queue=queue_name,
durable=False, auto_delete=True)
   AMQP_CHANNEL.exchange_declare(exchange=EXCHANGE_NAME,
type='topic', durable=True)
   AMQP_CHANNEL.queue_bind(
   queue=queue_name,
   exchange=EXCHANGE_NAME,
   routing_key=routing_key)
   consumer_tag = 'room' + self.id 


   AMQP_CHANNEL.basic_consume(queue=queue_name,
consumer_tag=consumer_tag)
   queue = yield AMQP_CONNECTION.queue(consumer_tag)
   while True:
   msg = yield queue.get()
   self.tell_msg(msg)

Note that the AMQP connection+channel are global. When the
server wants to forgot about a room, what do I have to do to
ensure that all resources will eventually be garbage
collected? Does it suffice to cancel the consumer? Do I have
to close the TimeoutDeferredQueue? Looking at the code in
protocol.py, it looks like there might be no way to make the
channel forget about the queue. Am I reading that correctly?
If so, that means I would need a new channel for each room, right?


That's not just init code, right? I mean you're also processing
messages.

Anyway, I think you want to call queue_delete like this (untested):

AMQP_CHANNEL.queue_delete(queue=queue_name)

dave


___
Mailing list: https://launchpad.net/~txamqp-user

Post to : txamqp-user@lists.launchpad.net

Unsubscribe : https://launchpad.net/~txamqp-user

More help   : https://help.launchpad.net/ListHelp



___
Mailing list: https://launchpad.net/~txamqp-user
Post to : txamqp-user@lists.launchpad.net
Unsubscribe : https://launchpad.net/~txamqp-user
More help   : https://help.launchpad.net/ListHelp
   



___
Mailing list: https://launchpad.net/~txamqp-user
Post to : txamqp-user@lists.launchpad.net
Unsubscribe : https://launchpad.net/~txamqp-user
More help   : https://help.launchpad.net/ListHelp


Re: [Txamqp-user] How to clean up

2010-06-16 Thread Ale
Hi Andrew,

What I use to clean up is using a stop_token object puting it in the queue
whenever I want close the queue. Although I'm not sure if it will garbage
collect all the objects though. See: http://dpaste.com/208100/

Hope it helps a tiny bit at least.

Cheers,

-- 
Ale.
___
Mailing list: https://launchpad.net/~txamqp-user
Post to : txamqp-user@lists.launchpad.net
Unsubscribe : https://launchpad.net/~txamqp-user
More help   : https://help.launchpad.net/ListHelp


Re: [Txamqp-user] How to clean up

2010-06-16 Thread Andrew Badr
When a room is created, it should start listening for messages. That's why
it starts listening in the init, though there is no actual
processing. Removing the consumer causes the queue to be deleted, so I don't
think that's necessary.

Here's my current attempt: http://dpaste.com/207704/

What I'm going for here -- not achieved yet -- is to have the same # of
objects at the 1st and 3rd call to gc.get_objects. My question is how to get
there. If you look at the unload method, that's my current attempt to
cleanup, but clearly it's either wrong or there's no right way to do
it. First time using each of AMQP, Twisted, and the gc module, so please
tell me what I'm doing wrong. Also, the number of extra objects (3rd call -
1st call) increases linearly with the argument to range() controlling how
many rooms are created, so I know it's something relating to room cleanup.

On Mon, Jun 14, 2010 at 7:56 PM, Dave Peticolas  wrote:

> On 06/14/2010 05:31 PM, Andrew Badr wrote:
>
>> Sorry if you get this message twice; launchpad sucks.
>>
>> I have a long-running server processes that listen for new messages from
>> some changing set of rooms. I want to make sure that when I'm done with a
>> particular room, all the resources associated with it are eventually freed.
>> Here's what my Room init code does:
>>
>>@inlineCallbacks
>>def startListening(self):
>>routing_key = 'rooms.' + self.id 
>>
>>queue_name = routing_key + '::' + CYCLONE_ID
>>AMQP_CHANNEL.queue_declare(queue=queue_name, durable=False,
>> auto_delete=True)
>>AMQP_CHANNEL.exchange_declare(exchange=EXCHANGE_NAME, type='topic',
>> durable=True)
>>AMQP_CHANNEL.queue_bind(
>>queue=queue_name,
>>exchange=EXCHANGE_NAME,
>>routing_key=routing_key)
>>consumer_tag = 'room' + self.id 
>>
>>AMQP_CHANNEL.basic_consume(queue=queue_name,
>> consumer_tag=consumer_tag)
>>queue = yield AMQP_CONNECTION.queue(consumer_tag)
>>while True:
>>msg = yield queue.get()
>>self.tell_msg(msg)
>>
>> Note that the AMQP connection+channel are global. When the server wants to
>> forgot about a room, what do I have to do to ensure that all resources will
>> eventually be garbage collected? Does it suffice to cancel the consumer? Do
>> I have to close the TimeoutDeferredQueue? Looking at the code in
>> protocol.py, it looks like there might be no way to make the channel forget
>> about the queue. Am I reading that correctly? If so, that means I would need
>> a new channel for each room, right?
>>
>>
> That's not just init code, right? I mean you're also processing messages.
>
> Anyway, I think you want to call queue_delete like this (untested):
>
> AMQP_CHANNEL.queue_delete(queue=queue_name)
>
> dave
>
>
> ___
> Mailing list: https://launchpad.net/~txamqp-user
> Post to : txamqp-user@lists.launchpad.net
> Unsubscribe : https://launchpad.net/~txamqp-user
> More help   : https://help.launchpad.net/ListHelp
>
___
Mailing list: https://launchpad.net/~txamqp-user
Post to : txamqp-user@lists.launchpad.net
Unsubscribe : https://launchpad.net/~txamqp-user
More help   : https://help.launchpad.net/ListHelp


Re: [Txamqp-user] How to clean up

2010-06-14 Thread Dave Peticolas

On 06/14/2010 05:31 PM, Andrew Badr wrote:

Sorry if you get this message twice; launchpad sucks.

I have a long-running server processes that listen for new messages 
from some changing set of rooms. I want to make sure that when I'm 
done with a particular room, all the resources associated with it are 
eventually freed. Here's what my Room init code does:


@inlineCallbacks
def startListening(self):
routing_key = 'rooms.' + self.id 
queue_name = routing_key + '::' + CYCLONE_ID
AMQP_CHANNEL.queue_declare(queue=queue_name, durable=False, 
auto_delete=True)
AMQP_CHANNEL.exchange_declare(exchange=EXCHANGE_NAME, 
type='topic', durable=True)

AMQP_CHANNEL.queue_bind(
queue=queue_name,
exchange=EXCHANGE_NAME,
routing_key=routing_key)
consumer_tag = 'room' + self.id 
AMQP_CHANNEL.basic_consume(queue=queue_name, 
consumer_tag=consumer_tag)

queue = yield AMQP_CONNECTION.queue(consumer_tag)
while True:
msg = yield queue.get()
self.tell_msg(msg)

Note that the AMQP connection+channel are global. When the server 
wants to forgot about a room, what do I have to do to ensure that all 
resources will eventually be garbage collected? Does it suffice to 
cancel the consumer? Do I have to close the TimeoutDeferredQueue? 
Looking at the code in protocol.py, it looks like there might be no 
way to make the channel forget about the queue. Am I reading that 
correctly? If so, that means I would need a new channel for each room, 
right?




That's not just init code, right? I mean you're also processing messages.

Anyway, I think you want to call queue_delete like this (untested):

AMQP_CHANNEL.queue_delete(queue=queue_name)

dave


___
Mailing list: https://launchpad.net/~txamqp-user
Post to : txamqp-user@lists.launchpad.net
Unsubscribe : https://launchpad.net/~txamqp-user
More help   : https://help.launchpad.net/ListHelp