# lock the jobs using ownerId try: cu = self.db.transaction() # <- dies here cu.execute("""UPDATE Jobs SET owner=? WHERE owner IS NULL AND status=?""", ownerId, jobstatus.WAITING) self.db.commit() except sqlerrors.DatabaseLocked: # do nothing if we fail to lock any rows; we'll be back... self.db.rollback() return 0 except: # unhandled exception; pass it up self.db.rollback() raise