SQLite Forum

How to circumvent "apsw.BusyError: BusyError: database is locked"?
Login
I use the following code (n2d contains the data to be written, n2d of different processes are not guaranteed to be different, they may be partially the same of completely the same). I don't understand how deadlock is caused and how to solved it? I basically just write to the db (except checking if the table is avaialble), so by rewriting the code the deadlock could be removed? Thanks. 

```
import apsw
conn = apsw.Connection(sys.argv[1])
c = conn.cursor()
c.execute('pragma busy_timeout=2147483647;')
c.execute('BEGIN TRANSACTION;')
try:
	c.execute('CREATE TABLE IF NOT EXISTS sqlar(name TEXT PRIMARY KEY, mode INT, mtime INT, sz INT, data BLOB)')
	for (name, len_data, zlib_data) in n2d:
		c.execute('REPLACE INTO sqlar VALUES(?, ?, ?, ?, ?)', [name, 0, 0, len_data, zlib_data])
	c.execute('COMMIT')
except:
	c.execute('ROLLBACK')
	raise
```