开发者

locked SQLite database errors with WSGI python app

I'm having issues making multiple ajax POST calls to functions that access a database in my web app using sqlite and mod-wsgi. I have no issues making requests to one function, but as soon as I call a different function, I started getting "database is locked" errors. I've tried setting the variables as global and just accessing them in the two functions, as well as opening and closing the database in each function, to no avail.

What's the proper way to interface with a database if you just have one application function in your code? Threads? Persistent connections?

I've used Django before, but wanted something bare-bone for this simple app running on my local machine.

The relevant section of code is:

con = sqlite3.connect("/var/www/Knowledge/eurisko.sqlite")
con.row_factory = sqlite3.Row
cursor = con.cursor()
cursor.execute("update notes_content set c1content=?, c2timestamp=?
where c0title=?", [content, timestamp, title])
con.commit()
cursor.close()
con.close()

The full file is here: http:/开发者_StackOverflow中文版/pastebin.com/7yuiZFi2

I'm running apache 2.2 on ubuntu 10 with libapache2-modwsgi and python 2.7.


See warnings about concurrent access from multiple processes in SQLite documentation.

http://www.sqlite.org/faq.html#q5

This information was provided on mod_wsgi list where question was also asked, but following up here.

This can be an issue because Apache/mod_wsgi supports both single and multi process configurations. Likely OP is using multi process configuration. Also see:

http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading

for description of Apache/mod_wsgi process/threading model.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜