cgi - Python deadlock error - Trying to retrieve key value from shelve -
here code updating record in shelve
def updaterecord(db, form): if not 'key' in form: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'missing key input' else: key = form['key'].value if key in db: record = db[key] else: person import person record = person(name='?',age='?') field in fieldnames: setattr(record, field, eval(form[field].value)) db[key] = record fields = record.__dict__ fields['key'] = key return fields
when trying retrieve value shelve getting error
>>> import shelve >>> db = shelve.open('class-shelve') >>> db['sue'].name traceback (most recent call last): file "<stdin>", line 1, in <module> file "/usr/lib/python2.7/shelve.py", line 121, in __getitem__ f = stringio(self.dict[key]) file "/usr/lib/python2.7/bsddb/__init__.py", line 270, in __getitem__ return _deadlockwrap(lambda: self.db[key]) # self.db[key] file "/usr/lib/python2.7/bsddb/dbutils.py", line 68, in deadlockwrap return function(*_args, **_kwargs) file "/usr/lib/python2.7/bsddb/__init__.py", line 270, in <lambda> return _deadlockwrap(lambda: self.db[key]) # self.db[key] keyerror: 'sue'
any insights whats going on?
assuming in first snippet, db
variable 'shelf' object, then, although line...
db[key] = record
...will add new key/value pair 'shelf', won't flush contents disk, won't available other processes sharing same 'shelf file'.
you can force 'shelf file' written disk adding line...
db.sync()
...after adding new key/value pair, can quite slow when 'shelf file' gets large, may not want call frequently.
Comments
Post a Comment