SQLite Forum

How to circumvent "apsw.BusyError: BusyError: database is locked"?
Login
I got this error.

```
  File "/xxx.py", line 23, in <module>
    c.execute('PRAGMA journal_mode=WAL;')
  File "src/cursor.c", line 1019, in APSWCursor_execute.sqlite3_prepare
  File "src/statementcache.c", line 386, in sqlite3_prepare
apsw.BusyError: BusyError: database is locked
```

So the following code would also cause the same error?

```
if c.execute('pragma journal_mode=wal;').fetchone()[0] <> 'wal':
      raise apsw.Error('Cannot change database to WAL')
```

So this is better as the first if just read the journal_mode and would not cause apsw.BusyError? Since WAL mode is persistent, as it as long as it is set once, the first `if` will always be false then the rest `pragma journal_mode=wal;` statement will not be called. Hence, there will be much less chance to see apsw.BusyError?

```
if c.execute('pragma journal_mode;').fetchone()[0] <> 'wal':
   if c.execute('pragma journal_mode=wal;').fetchone()[0] <> 'wal':
      raise apsw.Error('Cannot change database to WAL')
```