Michael C. Neel
neel at mediapulse.com
Tue Jan 27 13:17:15 EST 2004
I do this now for db connections: def db_connect(db="", user="", passwd="", host=""): global connection try: db = connection return db except NameError: connection = MySQLdb.connect( db=db, user=user, passwd=passwd, host=host) return connection (course this won't work in a 2.0 threaded MPM, as MySQLdb cursors are one-one with db connections). What I'm wanting to do as well is init my albatross app once to take advantage of it's template and page module caching. I admit this is an area where python starts to get fuzzy for me, so I'm not even sure if the above code is doing what I think it is. I can write an app wrapper like the one above for albatross no sweat, just if someone can give me a reassurance this is working like I think I'd feel better =) Mike > -----Original Message----- > From: Daniel West [mailto:dwmp at opti.cgi.net] > Sent: Tuesday, January 27, 2004 12:54 PM > To: mod_python at modpython.org > Subject: Re: [mod_python] Child process init handler > > > > Mike, > > Unfortunately mod_python is a little lacking when it comes to > initialization capabilities. If you've missed something in > the docs then > I've missed it too. As it turns out, it's not such a bad thing to do > initialization on the first request. Subsequent requests run > in the same > post-initialized environment (interpreter). For instance, > make a db module > for your database interface. On the first request, make a database > connection and store the connection object in the database > module. On the > next request, your database connection will still be there, > alive and ready > to use. > > I think it would be very nice, convenient and helpful to new > developers to > have PythonImport work under virtual domains and to provide a > method for > accessing the PythonOptions of the domain under which > PythonImport was > called. I know I spent several frustrating evenings, while taking up > mod_python, trying to figure out how to make initialization > work elegantly. > > -Dan > > > > At 11:55 AM 1/27/2004 -0500, you wrote: > >What I want to do: > > > > Run some initialization code when Apache spawns the child > >process. I do not want to call this handler for every > request, but I do > >want to have access to the configuration, specifically PythonOptions > > > >In looking though the docs, I'm not sure PythonInitHandler works this > >way, and PythonImport may not be able to access the PythonOption > >directives. Is there something I'm overlooking? > > > >Mike > > > >_______________________________________________ > >Mod_python mailing list > >Mod_python at modpython.org > >http://mailman.modpython.org/mailman/listinfo/mod_python > > > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python >
|