As the documentation of
shelve.Shelf objects are not thread
The shelve module does not support concurrent read/write access to shelved objects.
To write to a
Shelf object in an environment where multiple threads may end
up writing to it, use a global
from threading import Lock import shelve mutex = Lock() mutex.acquire() db = shelve.open(db_name) # write to db db.close() mutex.release()