peewee: Sqlite database locked - regression introduced in 2.4.5?
Below an excerpt from my CherryPy app.
The app receives bursts of ajax calls to cncprogram_done. Sometimes just 1 or 2 calls, sometimes up to 10 or 20 at a time (I will eventually optimize it, but for now I’m OK with it).
I just upgraded to Peewee 2.8.3 and only the first call of each burst works, the other calls say peewee.OperationalError: database is locked while executing part.save().
I tried to revert to older versions, and I found out that with Peewee 2.4.4 works well and with the 2.4.5 fails.
I reverted back to 2.4.4 on the production server and everything seems to work fine.
Any idea whether I am doing something wrong or this is really a regression? Where do I start investigating?
Here is (part of) the code:
db = peewee.SqliteDatabase(path_name + '/doc.db', threadlocals=True)
class PeeweeModel(peewee.Model):
class Meta:
database = db
class CncProgramPart(PeeweeModel):
sheet = peewee.ForeignKeyField(CncProgramSheet, related_name='parts')
part_number = peewee.CharField()
time_finished = peewee.DateTimeField(default=0)
remake = peewee.BooleanField(default=False)
comment = peewee.CharField(default='')
def render(self, settings):
return render('cncprogram_edit_part_row.html',
{'part': self, 'settings': settings})
class DocFinder:
@cherrypy.expose
def cncprogram_done(self, rowid, value):
with db.transaction():
checked = value == 'true'
now = time.time()
part = CncProgramPart.get(CncProgramPart.id == rowid[9:])
if checked and not part.remake and not part.comment:
part.time_finished = now
part.comment = ''
part.remake = False
part.save()
elif part.time_finished:
part.time_finished = 0
part.save()
return part.render(Settings())
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 40 (40 by maintainers)
Commits related to this issue
- py3k fix. Refs #1071. — committed to coleifer/peewee by coleifer 8 years ago
Another thing you should always be doing is specifying
journal_mode='wal'when you instantiate your Sqlite database. This allows multiple readers to co-exist with a single writer, and I think this may also magically solve your issues:I have something awesome you can try…
It’s currently only in master branch, but if you want to try it out it should solve your problem.
In the
playhouse.sqliteqmodule is a class namedSqliteQueueDatabase. Replace this:With this:
At the same time, remove all calls to db.connect() and db.close().