piskvorky / sqlitedict

Persistent dict, backed by sqlite3 and pickle, multithread-safe.
Apache License 2.0
1.17k stars 131 forks source link

Loading a corrupted database does not raise exception gracefully #129

Open mtanti opened 3 years ago

mtanti commented 3 years ago

If you try to load a file which isn't a database, you get the following error:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "...\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "...\lib\site-packages\sqlitedict.py", line 396, in run
    conn.execute('PRAGMA journal_mode = %s' % self.journal_mode)
sqlite3.DatabaseError: file is not a database

The problem here is that the error raises in a thread which then dies and leave your console hanging, probably due to missing multithread error handling.

I find it strange that I should get multithreading when I use SqliteDict and not SqliteMultithread, which I traced to the _new_conn method. A quick fix would be to avoid using multithreading when none is requested in order to avoid this sort of error when not using multithreading at least.

piskvorky commented 3 years ago

Thanks for reporting @mtanti . Will you be able to look into this, submit a PR?

mtanti commented 3 years ago

Thanks for reporting @mtanti . Will you be able to look into this, submit a PR?

No I don't have time, sorry.