Queue object in Zope products
Hello, I am working on a Zope product that throws data into a queue that is monitored by a number (3) of producers. Producers can talk to Corba objects. I use omniOrb for this. Producers take out data from the outqueue and send it to other Corba objects. This is the basic setup: class SIPConnector(SimpleItem): """Connector class""" def __init__(self, id, title): self.id = id self.title = title self.n = 3 # number of producers def initConnectionPool(self): self._v_outqueue = Queue.Queue() for i in range(self.n): id = 'tc' + str(i) tp = SIPProducer(id) thread.start_new_thread(self.runProducer, (tc, self._v_outqueue,)) def post(self, sid, to, msg): self._v_outqueue.put(sid, to, msg) def runProducer(self, tp, oq): # connect to Corba dispatcher tp.orb, tp.cmf = tp._connect() while 1: try: msg = oq.get(0) print msg tp..cmf.xmit(msg) except Queue.Empty: time.sleep(0.05) class SIPProducer(CorbaBaseClass): def __init__(self, id): self.id = id This basically works. However, if I put msg's in the queue with the post method from a page template, and I do this a couple of times, quickly, I get an attribute error on self._v_inqueue. It is somehow gets lost. Does anyone know what I am doing wrong here? What happened to the 'lost' queue? Cheers, Joost -- Brain, v. [as in "to brain"]: To rebuke bluntly, but not pointedly; to dispel a source of error in an opponent. -- Ambrose Bierce, "The Devil's Dictionary" -- Joost van Lawick van Pabst E: joost@lawick.nl W: http://www.lawick.nl/
Joost van Lawick wrote:
This basically works. However, if I put msg's in the queue with the post method from a page template, and I do this a couple of times, quickly, I get an attribute error on self._v_inqueue. It is somehow gets lost. Does anyone know what I am doing wrong here? What happened to the 'lost' queue?
'_v' attributes are stored on a per-database-connection basis, which is sort of like per-thread storage. If you hit it several times quickly, you are likely to get served by a thread that has a copy of the object with no '_v_inqueue'. At a quick glance, you could probably get around this by using a module-level registry of inqueues. Cheers, Evan @ 4-am
Thanks for all replies. I understand now why this did not work. Using module variables solved the problem. Cheers! Joost On Thu, Oct 24, 2002 at 09:38:59AM -0500, Evan Simpson wrote:
Joost van Lawick wrote:
This basically works. However, if I put msg's in the queue with the post method from a page template, and I do this a couple of times, quickly, I get an attribute error on self._v_inqueue. It is somehow gets lost. Does anyone know what I am doing wrong here? What happened to the 'lost' queue?
'_v' attributes are stored on a per-database-connection basis, which is sort of like per-thread storage. If you hit it several times quickly, you are likely to get served by a thread that has a copy of the object with no '_v_inqueue'.
At a quick glance, you could probably get around this by using a module-level registry of inqueues.
Cheers,
Evan @ 4-am
-- Joost van Lawick van Pabst E: joost@lawick.nl W: http://www.lawick.nl/
volatile lifetimes are only as long in as the object is in a non-ghost state. you can't reliably predict a period for this, but you can use a __setstate__ hook, to capture volatiles before the object is ghostified. also its good practice to set a class attribute of the volatile to none, or use a computed attribute to set the initial value of a volatile, imo. -kapil On Thursday 24 October 2002 01:05 am, Joost van Lawick wrote:
Hello,
I am working on a Zope product that throws data into a queue that is monitored by a number (3) of producers. Producers can talk to Corba objects. I use omniOrb for this. Producers take out data from the outqueue and send it to other Corba objects. This is the basic setup:
class SIPConnector(SimpleItem): """Connector class"""
def __init__(self, id, title): self.id = id self.title = title self.n = 3 # number of producers
def initConnectionPool(self): self._v_outqueue = Queue.Queue()
for i in range(self.n): id = 'tc' + str(i) tp = SIPProducer(id) thread.start_new_thread(self.runProducer, (tc, self._v_outqueue,))
def post(self, sid, to, msg): self._v_outqueue.put(sid, to, msg)
def runProducer(self, tp, oq): # connect to Corba dispatcher tp.orb, tp.cmf = tp._connect()
while 1: try: msg = oq.get(0) print msg tp..cmf.xmit(msg) except Queue.Empty: time.sleep(0.05)
class SIPProducer(CorbaBaseClass):
def __init__(self, id): self.id = id
This basically works. However, if I put msg's in the queue with the post method from a page template, and I do this a couple of times, quickly, I get an attribute error on self._v_inqueue. It is somehow gets lost. Does anyone know what I am doing wrong here? What happened to the 'lost' queue?
Cheers,
Joost
participants (3)
-
Evan Simpson -
Joost van Lawick -
kapil thangavelu