Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pickledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,19 @@ def deldb(self):
return True

def _loaddb(self):
'''Load or reload the json info from the file'''
self.db = simplejson.load(open(self.loco, 'rb'))
'''Load or reload the json info from the file'''
fh = open(self.loco, 'rb')
try:
self.db = simplejson.load(fh)
except Exception, reason:
self.db={}
#This assures that the file is not locked if json.load
#fails e.g. due to corrupt file..
#Clients of pickledb can then restore or delete the file.
fh.close()
raise Exception, reason
#no reason to keep the file handle open.
fh.close()

def _dumpdb(self, forced):
'''Write/save the json dump into the file'''
Expand Down