Re: [Twisted-Python] db connections

2009-03-28 Thread Pet
On Sat, Mar 28, 2009 at 2:32 AM, Enrique Samson Jr. wrote: > On Wed, 2009-03-25 at 11:00 +0100, Pet wrote: >> > Hi, >> > >> > thanks for example! >> > In that way, I'm getting error: >> > >> > exceptions.AttributeError: MyProtocol instance has no attribute 'factory' >> > >> > How can MyProtocol ac

Re: [Twisted-Python] db connections

2009-03-27 Thread Enrique Samson Jr.
On Wed, 2009-03-25 at 11:00 +0100, Pet wrote: > > Hi, > > > > thanks for example! > > In that way, I'm getting error: > > > > exceptions.AttributeError: MyProtocol instance has no attribute 'factory' > > > > How can MyProtocol access self.factory.dbcon? > > Ups! I didn't followed exactly your exam

Re: [Twisted-Python] db connections

2009-03-25 Thread Pet
On Wed, Mar 25, 2009 at 10:22 AM, Pet wrote: > On Tue, Mar 24, 2009 at 6:10 PM, Alvin Delagon wrote: >> Something like this: >> >> from twisted.protocols import basic >> from twisted.internet import protocol, reactor >> from twisted.enterprise import adbapi >> >> class MyProtocol(basic.LineReceiv

Re: [Twisted-Python] db connections

2009-03-25 Thread Pet
On Tue, Mar 24, 2009 at 6:10 PM, Alvin Delagon wrote: > Something like this: > > from twisted.protocols import basic > from twisted.internet import protocol, reactor > from twisted.enterprise import adbapi > > class MyProtocol(basic.LineReceiver): >     def __init__(self): >     pass > >     d

Re: [Twisted-Python] db connections

2009-03-24 Thread Rob Hoadley
Sorry I apologize... that email I wrote wasn't very clear. I've done it in the factory like below. Slightly different from Alvin. I've used the factory __init__ to pass on the logical_db information... then I have a dbpool created later. That way I can do development and production based on EN

Re: [Twisted-Python] db connections

2009-03-24 Thread Alvin Delagon
Something like this: from twisted.protocols import basic from twisted.internet import protocol, reactor from twisted.enterprise import adbapi class MyProtocol(basic.LineReceiver): def __init__(self): pass def lineReceived(self, line): ### dbcon can be accessed via self.fa

Re: [Twisted-Python] db connections

2009-03-24 Thread Pet
On Tue, Mar 24, 2009 at 5:04 PM, Rob Hoadley wrote: > You'd want to use a connection pool to manage the db interaction. > Your server is pretty unusable after a db connection failure.  I've > used the connection pool before with a cp_min of 1 and a cp_max of 2. Honestly speaking, I don't understa

Re: [Twisted-Python] db connections

2009-03-24 Thread Pet
On Tue, Mar 24, 2009 at 2:45 PM, Alvin Delagon wrote: > Put self.dbcon in the MyFactory class. MyProtocol instances can access it > via self.factory. Thanks for your help! Could you give me an example? I'm getting an error MyProtocol instance has no attribute 'factory' if I do as you suggested.

Re: [Twisted-Python] db connections

2009-03-24 Thread Rob Hoadley
You'd want to use a connection pool to manage the db interaction. Your server is pretty unusable after a db connection failure. I've used the connection pool before with a cp_min of 1 and a cp_max of 2. http://twistedmatrix.com/documents/8.2.0/api/twisted.enterprise.adbapi.ConnectionPool.html O

Re: [Twisted-Python] db connections

2009-03-24 Thread Alvin Delagon
Put self.dbcon in the MyFactory class. MyProtocol instances can access it via self.factory. On Tue, Mar 24, 2009 at 6:10 PM, Pet wrote: > Hi, > > I've wrote an daemon which does some queries to db and sends response > back to client. Do I need to make for every request from client (new > instan

[Twisted-Python] db connections

2009-03-24 Thread Pet
Hi, I've wrote an daemon which does some queries to db and sends response back to client. Do I need to make for every request from client (new instance of MyProtocol) a new connection to DB? Or can I somehow prepare connection, so I could save some time? Maybe make connection in Factory and pass