Joshua Schmidlkofer
menion at asylumwear.com
Tue Dec 9 13:32:15 EST 2003
On Tue, 2003-12-09 at 13:17, Michael S. Fischer wrote: > Indeed, when using the publisher handler, you are supposed to return the > content. > > I don't understand your code, though. What is the idea behind its > arrangement? > > Normally when I make mod_python.publisher scripts, I do something like: > > <snip> > _conn = None > def _getConnection(...): > global _conn > if not _conn: > _conn = ... > return _conn > > def index(req, params...): > ... > conn = _getConnection(...) > ... > return content > </snip> > Here is an example, that is producing the problem for me: import psycopg, os, copy, types _DSN = 'dbname=mydb user=myuser host=dbserver' _conn = None def getConnection(): global _conn if not _conn: _conn = psycopg.connect(_DSN) return _conn.cursor() def index(**kwargs): cursor = getConnection() cursor.execute("select * from bad") content = """ <html><head><title>test</test></head> <body> Test:<br>%s </body></html> """ tmp = "" for x in cursor.fetchall(): tmp += "%s<br>" % str(x) cursor.close() del cursor return content % tmp
|