question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sqlite database locked - regression introduced in 2.4.5?

See original GitHub issue

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())

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:40 (40 by maintainers)

github_iconTop GitHub Comments

1reaction
coleifercommented, Sep 20, 2016

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:

db = SqliteDatabase('foo.db', pragmas=[('journal_mode', 'wal')])
1reaction
coleifercommented, Sep 20, 2016

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.sqliteq module is a class named SqliteQueueDatabase. Replace this:


db = peewee.SqliteDatabase('test.db')

With this:

from playhouse.sqliteq import SqliteQueueDatabase
db = SqliteQueueDatabase('t.db', readers=4, autostart=True)

At the same time, remove all calls to db.connect() and db.close().

Read more comments on GitHub >

github_iconTop Results From Across the Web

Release History Of SQLite
Release History. This page provides a high-level summary of changes to SQLite. For more detail, see the Fossil checkin logs at ...
Read more >
SQLite database locking errors cause fatal errors - Drupal
Problem/Motivation. SQLite does not support row level locks, so when it executes a write statement it locks the entire database.
Read more >
532555 - sqlite error : database is locked - chromium - Monorail
1503, mint 13. Flash Version: 18.0.0.233 (Disabled) This [mis]behavior started after updating Chrome to version 45.0.2454.85
Read more >
Java prog#7. Database is locked problem solution ... - YouTube
Java prog#7. Database is locked problem solution in Java Netbeans and Sqlite (mysql).
Read more >
SQLite/GPKG database locked during canvas refresh - QGIS ...
As above, during canvas refresh (only sqlite layers), when redraw isn't finished - hit "save edits" causes SQLite error "database is locked".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found