Mailing List Archive

Python+Apache+Oracle+???Persistent database connection???
Hi,

Can any of you Python gurus tell me if the following would be
easy/possible/impossible and perhaps point me in the right direction???

I have Python (1.5.1), Apache (1.3.6), Oracle (8.0.5), PyApache (4.16),
and DCOracle (Python interface to Oracle - 1.2.1) on my Linux box
(Caldera OpenLinux 2.2). It works fine.

But what I would like to have is a persistent database connection for
each Apache child server that is accessible to every Python script that
is fired up by that server. This because logging on to Oracle is VERY
expensive compared to simple database accesses. As far as I can see this
isn't possible with PyApache/DCOracle at present.

Now my Python level is middling, I have no experience in embedding or
extending Python, or in writing Apache modules, and my C is *VERY*
rusty, but from browsing some of the documentation and code this is my
limited understanding of what happens every time when Apache calls
PyApache to run a Python script:
Py_NewInterpreter
execute Python script
Py_EndInterpreter

Logging on to Oracle in DCOracle returns a 'Connection' object. Am I
right in thinking that this object and every other Python object
automatically and ineluctably get destroyed by the Py_EndInterpreter
call??? If yes, is there any way to save it away 'somewhere' and get it
back later 'somehow' after the next Py_NewInterpreter call??? Or would
this require some sort of coordination between the PyApache and DCOracle
code??? Or is it impossible???

Any help gratefully appreciated.

Regards,
Philip Payne
Python+Apache+Oracle+???Persistent database connection??? [ In reply to ]
Philip -

You can acheive persistant database connectivity by converting your cgi apps
to pcgi. pcgi (persistant cgi), was developed by Jeff Bauer, and is
available as a component of Zope (http://www.zope.org). You can use pcgi
with or without Zope.

Good luck.

Bill

-----Original Message-----
From: Philip Payne [mailto:pnpayne@swissonline.ch]
Sent: Friday, August 20, 1999 2:50 PM
To: python-list@python.org
Subject: Python+Apache+Oracle+???Persistent database connection???


Hi,

Can any of you Python gurus tell me if the following would be
easy/possible/impossible and perhaps point me in the right direction???

I have Python (1.5.1), Apache (1.3.6), Oracle (8.0.5), PyApache (4.16),
and DCOracle (Python interface to Oracle - 1.2.1) on my Linux box
(Caldera OpenLinux 2.2). It works fine.

But what I would like to have is a persistent database connection for
each Apache child server that is accessible to every Python script that
is fired up by that server. This because logging on to Oracle is VERY
expensive compared to simple database accesses. As far as I can see this
isn't possible with PyApache/DCOracle at present.

Now my Python level is middling, I have no experience in embedding or
extending Python, or in writing Apache modules, and my C is *VERY*
rusty, but from browsing some of the documentation and code this is my
limited understanding of what happens every time when Apache calls
PyApache to run a Python script:
Py_NewInterpreter
execute Python script
Py_EndInterpreter

Logging on to Oracle in DCOracle returns a 'Connection' object. Am I
right in thinking that this object and every other Python object
automatically and ineluctably get destroyed by the Py_EndInterpreter
call??? If yes, is there any way to save it away 'somewhere' and get it
back later 'somehow' after the next Py_NewInterpreter call??? Or would
this require some sort of coordination between the PyApache and DCOracle
code??? Or is it impossible???

Any help gratefully appreciated.

Regards,
Philip Payne

--
http://www.python.org/mailman/listinfo/python-list
Python+Apache+Oracle+???Persistent database connection??? [ In reply to ]
ScherBi@BAM.com wrote:
> You can acheive persistant database connectivity by converting
> your cgi apps to pcgi. pcgi (persistant cgi), was developed by
> Jeff Bauer, and is available as a component of Zope
> (http://www.zope.org). You can use pcgi with or without Zope.

A minor correction:

The Persistent CGI protocol was already developmented by
Digital Creations (when I was still in my nappies). I'm
merely its current custodian.

Jeff Bauer
Rubicon Reseach
"There ought to be limits to freedom."
http://www.gwbush.com
Python+Apache+Oracle+???Persistent database connection??? [ In reply to ]
In case anyone is interested, the following solution was sent to me by
e-mail by Andrew Csillag:

Actually, there sorta is. With PyApache 4.14 and up, there is something
that gets put into the builtin namespace, it's called __persistdict__,
which is a persistant dictionary in that it doesn't get wiped between
requests. A point to note tho is that you really can only put in C
objects, cause python objects won't work (mostly because the module the
object came from was since destroyed). I've done this with excellent
results with oracledb, with DCOracle it gets a bit trickier. You wind
up having to do something like this (caveat programmer: I haven't
actually tried it, but I've worked with other objects that worked
similarly) to use the connection:

to save the connection:
#you might be able to get away without using __dict__ and perhaps
could
#just use conn._d, but there's a setattr hook and I didn't really
#look at it to see what it did, so the below should work for sure
__persistdict__['my_oracle_connection'] = conn.__dict__['_d']

to use the saved connection:
import DCOracle.ocidb
class dummy: pass
conn = dummy()
conn._d = __persistdict__['my_oracle_connection']
conn.__class__ = DCOracle.ocidb.ocidb

It it a bit ugly? Yup, but it should work more or less. While oracledb
isn't quite as nice in general, you can just stick it into the dict
(although, there is some mucking around with the dbi module to make IT
work).