[mod_python] mod_python and sqlite

Colin Bean ccbean at gmail.com
Wed Jan 10 14:18:30 EST 2007


Hi Richard,

Could it be concurrency problems due to two apache instances trying to
write to the database simultaneously?  Does it always fail on the
first request?  Does it fail if you limit apache to a single child
process?

I'm looking at sqlite3 that came with python2.5 right now, so I'm not
sure if the behavior and errors are the same, but I opened the same
database from two different python interpreters and tried to insert a
value from each one.  If I executed the first insert, then executed a
second insert from the other interpreter (before committing the first
one), it failed with an sqlite3.OperationalError.  I tried again with
the isolation level set to None on both connections (so sqlite will
autocommit after each statement), and both inserts worked.

So I'd also try
con = sqlite.connect("file.db", isolation_level=None)
and see if that helps.

hth,
Colin


On 1/10/07, Richard Lewis <richardlewis at fastmail.co.uk> wrote:
> On Wednesday 10 January 2007 17:45, Michael Rasmussen wrote:
> > On Wed, 10 Jan 2007 17:28:14 +0000
> >
> > Richard Lewis <richardlewis at fastmail.co.uk> wrote:
> > > The problem I have is that when I try to execute the SQL UPDATE
> > > query, the database raises the exception "Database error: unable to
> > > open database file".
> > > I've checked to make sure that I can execute the code correctly from
> > > the Python interpreter, and I can.
> > >
> > > So I also made sure that Apache has write permission to the database
> > > file by setting the permissions to rwxrwxrwx!
> >
> > You are sure your webserver does not run in a jail/chroot environment
> > in which case a running instance of the webserver might never have
> > access to the required directory?
> >
> Um, not as far as I know. Its just Apache 2.2 on Debian (unstable).
>
> > What does the webservers errorlog show?
>
> [Wed Jan 10 17:12:23 2007] [error] [client c_ip] PythonHandler session:
> Traceback (most recent call last):, referer: http://server/
>
> [Wed Jan 10 17:12:23 2007] [error] [client c_ip] PythonHandler session:
> File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, in
> HandlerDispatch\n    result = object(req), referer: http://server/
>
> [Wed Jan 10 17:12:23 2007] [error] [client c_ip] PythonHandler session:
> File "/var/www/session.py", line 50, in handler\n    cur.execute("UPDATE
> users SET in_use=1, name=\\"%s\\", started=\\"%s\\" WHERE id=%d" % \\,
> referer: http://server/
>
> [Wed Jan 10 17:12:23 2007] [error] [client c_ip] PythonHandler session:
> File "/usr/lib/python2.4/site-packages/sqlite/main.py", line 237, in
> execute\n    self.con._begin(), referer: http://server/
>
> [Wed Jan 10 17:12:23 2007] [error] [client c_ip] PythonHandler session:
> File "/usr/lib/python2.4/site-packages/sqlite/main.py", line 503, in _begin\n
> self.db.execute("BEGIN"), referer: http://server/
>
> [Wed Jan 10 17:12:23 2007] [error] [client c_ip] PythonHandler session:
> DatabaseError: unable to open database file, referer: http://server/
>
> Cheers,
> Richard
> --
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> Richard Lewis
> Sonic Arts Research Archive
> http://www.sara.uea.ac.uk/
> JID: ironchicken at jabber.earth.li
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>


More information about the Mod_python mailing list