[DB-SIG] Handling an open database connection after a fork?
mal at egenix.com
Sat Jan 12 14:14:03 CET 2008
On 2008-01-11 17:35, Mike Meyer wrote:
> I have an application that's using oracle (via cx_Oracle) to log
> events (among other things). It runs in multiple processes, forking
> new processes as it needs them.
> db = cx_Oracle.connect(.....)
> cu = db.cursor()
> [do various things, including sql inserts and commits]
> if fork():
> # Parent wants to keep the existing database connection.
> # Child wants a database connection.
> So the question is - what should the child do to get a database
> connection? Can it just keep using the existing db & cu variables? If
> not, does it need to do anything special, or avoid doing anything, in
> order to not disrupt the parent processes use of those variables?
That depends on the database module you're using.
It may be enough to close all connections and reopen them
in the fork. In other cases, you need to reload the database
module as well (e.g. if the module sets up a work environment
that holds caches, etc.).
In general, it's better to avoid all this and only load the module
for the first time after the fork (both in the parent and child
Professional Python Services directly from the Source (#1, Jan 12 2008)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
More information about the DB-SIG