[DB-SIG] Which Oracle extension to use?
anthony at computronix.com
Tue Nov 18 14:18:33 EST 2003
On Tue, 2003-11-18 at 11:04, Martin Möllenbeck wrote:
> sorry, must go to the list
> Andy Todd wrote:
> > Guido van Rossum wrote:
> >> We're about to start developing for Oracle 9 (or is that 9i???) on
> >> Linux. I know that there are several Oracle extensions for Python,
> >> but I've never used either of them. If you have relevant experience,
> >> please let me know (private mail will be fine).
> >> --Guido van Rossum (home page: http://www.python.org/~guido/)
> >> _______________________________________________
> >> DB-SIG maillist - DB-SIG at python.org
> >> http://mail.python.org/mailman/listinfo/db-sig
> > Guido,
> > There are two that I know of and have used successfully;
> > cx_Oracle : http://www.computronix.com/utilities.shtml#Oracle
> > DCOracle2 : http://www.zope.org/Members/matt/dco2
> > cx_Oracle is more actively maintained (and there are a number of other
> > Oracle utilities on that page) but both work well.
> > It's 9i by the way. Unless you've managed to get an early copy of 10g ;-)
> > Regards,
> > Andy
> but when threadsafety is important, have a closer look to the docs of
> the modules.
Hmm, yes. It looks like the DCOracle2 module is not following the
specification correctly -- or my understanding is flawed and I'd
appreciate some correction.... :-)
The DCOracle2 module states the following:
DCOracle2.threadsafety - this is the thread-safety-ness of DCOracle2,
the constant 3. This means that threads may share the module,
connections and cursors. Note that programming errors are still possible
without a mutex to serialize resources between threads.
Note carefully the last statement which conflicts with the statement
from the DB API which I reproduce here.
Sharing in the above context means that two threads may use a resource
without wrapping it using a mutex semaphore to implement resource
locking. Note that you cannot always make external resources thread safe
by managing access using a mutex: the resource may rely on global
variables or other external sources that are beyond your control.
Note the first statement in the specification. My own testing has
demonstrated quite clearly that even with OCI_THREADED mode, you
__CANNOT__ share cursors with multiple threads without using a mutex.
Just for fun, try running this code with DCOracle2 -- watch it crash and
burn.... :-) I believe DCOracle2's documentation is inaccurate. Anyone
care to set me straight??
connection = DCOracle2.connect("app/dev at dev")
cursor = connection.cursor()
cursor.execute("select count(*) from SOMETABLE")
count, = cursor.fetchone()
print threadNum, "Count:", count
print "Starting threads...."
threads = 
for i in range(15):
thread = threading.Thread(None, PerformQuery, args = (i,))
for thread in threads:
print "All done...."
> DB-SIG maillist - DB-SIG at python.org
anthony at computronix.com
Distinctive Software. Real People.
Suite 200, 10216 - 124 Street NW
Edmonton, AB, Canada T5N 4A3
Phone: (780) 454-3700
Fax: (780) 454-3838
More information about the DB-SIG