Re: [cx-oracle-users] Session Pooling with cx_Oracle
Brought to you by:
atuining
From: Yoel S. <yoe...@gm...> - 2008-01-15 01:41:12
|
Hi Anthony, Wow, this works too. So there are two ways of acquiring the session pool 1. Specifying pool paramater in the cx_Oracle.Connection string. cx_Oracle.Connection(user=3D'scott',password=3D'tiger',dsn=3D'xe',pool=3DSc= ottPool) 2. A simpler way from you. conn =3D pool.acquire() Thanks for your reply! Cheers, On Jan 10, 2008 10:39 PM, Anthony Tuininga <ant...@gm...> wrote: > I'm not sure what the original code you posted is intending to > accomplish so if you know, please enlighten me. :-) > > All you need to do is: > > pool =3D cx_Oracle.SessionPool(......) # you seem to have gotten this > alright > connection =3D pool.acquire() > > Use the connection as you like. When the connection goes out of scope > it will automatically be returned to the pool. If you want to force > that to occur sooner, use > > pool.release(connection) > > That should be it. > > On Jan 9, 2008 11:23 PM, Yoel Susanto <yoe...@gm...> wrote: > > Hi Tamas, > > > > Thank you for replying, however when i tried to execute db =3D > > dbfun('tiger','scott','local'), it failed. > > > > > > >>> db =3D dbfun('tiger','scott','local') > > Traceback (most recent call last): > > File "<stdin>", line 1, in ? > > TypeError: __init__() takes exactly 1 argument (4 given) > > > > Is there something that i need to change in the class definition? > > > > ANYWAY, I have found out how to create a pool using > cx_Oracle.SessionPool > > object. > > > > Here is what I did, interactively: > > > > =3D=3D I created a pool called ScottPool with maximum connection of 2 = =3D=3D > > >>> ScottPool =3D > > > cx_Oracle.SessionPool(user=3D'scott',password=3D'tiger',dsn=3D'xe',min=3D= 1,max=3D2,increment=3D1) > > > > =3D=3D I create a session to use ScottPool by passing pool=3DScottPool) > > >>> con1 =3D > > > cx_Oracle.Connection(user=3D'scott',password=3D'tiger',dsn=3D'xe',pool=3D= ScottPool) > > >>> con2 =3D > > > cx_Oracle.Connection(user=3D'scott',password=3D'tiger',dsn=3D'xe',pool=3D= ScottPool) > > >>> con3 =3D > > > cx_Oracle.Connection(user=3D'scott',password=3D'tiger',dsn=3D'xe',pool=3D= ScottPool) > > Traceback (most recent call last): > > File "<stdin>", line 1, in ? > > cx_Oracle.DatabaseError: ORA-24418: Cannot open further sessions. > > > > It seems to be working! > > > > > > > > > > On Jan 10, 2008 4:19 AM, Tam=E1s Gul=E1csi < gt-dev@gthomas.homelinux.o= rg> > > wrote: > > > Hi Yoel, > > > > > > The usage of your quoted example is like: > > > > > > # usage: > > > > > > db =3D dbfun('tiger', 'scott', 'local') > > > cx =3D db.connect() > > > cu =3D cx.cursor() > > > cu.execute('SELECT * FROM CAT WHERE table_name LIKE :1', ['%X%']) > > > print cu.description > > > for row in cu: > > > print row > > > cu.close() > > > cx.close() > > > > > > Tam=E1s Gul=E1csi > > > > > > > > > > > > cx-...@li... =EDrta: > > > > Send cx-oracle-users mailing list submissions to > > > > cx-...@li... > > > > > > > > To subscribe or unsubscribe via the World Wide Web, visit > > > > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > > or, via email, send a message with subject or body 'help' to > > > > cx-...@li... > > > > > > > > You can reach the person managing the list at > > > > cx-...@li... > > > > > > > > When replying, please edit your Subject line so it is more specific > > > > than "Re: Contents of cx-oracle-users digest..." > > > > > > > > > > > > Today's Topics: > > > > > > > > 1. Session Pooling with cx_Oracle (Yoel Susanto) > > > > > > > > > > > > > ---------------------------------------------------------------------- > > > > > > > > Message: 1 > > > > Date: Wed, 9 Jan 2008 16:27:08 +0800 > > > > From: "Yoel Susanto" <yoe...@gm...> > > > > Subject: [cx-oracle-users] Session Pooling with cx_Oracle > > > > To: cx-...@li... > > > > Message-ID: > > > > <380...@ma... > > > > > Content-Type: text/plain; charset=3D"iso-8859-1" > > > > > > > > > > > > > > > > > Hi, > > > > > > > > I am new with python & cx_Oracle. Currently I have a zeocluster > hosting > > my > > > > web applications. > > > > The developer uses cx_Oracle to connect to Oracle DB. > > > > > > > > return cx_Oracle.Connection(username/password@dbname) > > > > > > > > I found out that there's SessionPool object which we can use to poo= l > > > > database connection. > > > > I am hoping someone could teach me on how to do that. > > > > > > > > I found this piece of code from > > > > http://osdir.com/ml/python.db.cx-oracle/2005-08/msg00002.html > > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D > > > > class myConnection(cx_Oracle.Connection): > > > > def __init__(self, *args, **kwargs): > > > > cx_Oracle.Connection.__init__(self, *args, **kwargs) > > > > self.pool =3D kwargs.get('pool',None) > > > > def close(self): > > > > if self.pool: self.pool.release(self) > > > > else: super(myConnection, self).close() > > > > > > > > class dbfun(object): > > > > def __init__(self): > > > > self.pool=3DmySessionPool(user=3D'name', password=3D'pw', > dsn=3D'local', > > > > min=3D2, max=3D16, increment=3D2) > > > > def connect(self, *args, **kwargs): > > > > if kwargs.get('user','NoUser') =3D=3D 'name': > > > > kwargs.setdefault('pool', self.pool) > > > > return myConnection(*args, **kwargs) > > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D > > > > > > > > but being new to python, I don't really understand on how to use it > for > > my > > > > application. > > > > > > > > Can anyone enlighten me? > > > > > > > > Thanks in advance for any help. > > > > > > > > Cheers, > > > > Yoel > > > > -------------- next part -------------- > > > > An HTML attachment was scrubbed... > > > > > > > > ------------------------------ > > > > > > > > > > > ------------------------------------------------------------------------- > > > > Check out the new SourceForge.net Marketplace. > > > > It's the best place to buy or sell services for > > > > just about anything Open Source. > > > > > > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketpl= ace > > > > > > > > ------------------------------ > > > > > > > > _______________________________________________ > > > > cx-oracle-users mailing list > > > > cx-...@li... > > > > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > > > > > > > > > > End of cx-oracle-users Digest, Vol 20, Issue 2 > > > > ********************************************** > > > > > > > > > > ------------------------------------------------------------------------- > > > Check out the new SourceForge.net Marketplace. > > > It's the best place to buy or sell services for > > > just about anything Open Source. > > > > > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketpl= ace > > > _______________________________________________ > > > cx-oracle-users mailing list > > > cx-...@li... > > > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > > > > > > > > ------------------------------------------------------------------------- > > Check out the new SourceForge.net Marketplace. > > It's the best place to buy or sell services for > > just about anything Open Source. > > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketpl= ace > > _______________________________________________ > > cx-oracle-users mailing list > > cx-...@li... > > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > > > > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketpl= ace > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > |