python / cpython

The Python programming language
https://www.python.org/
Other
60k stars 29.04k forks source link

shelve update fails on "large" entry #36176

Closed 4223e389-0246-440b-97cf-aa7e4eb01e0e closed 19 years ago

4223e389-0246-440b-97cf-aa7e4eb01e0e commented 22 years ago
BPO 523425
Nosy @brettcannon, @facundobatista

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = created_at = labels = ['library'] title = 'shelve update fails on "large" entry' updated_at = user = 'https://bugs.python.org/jvickroy' ``` bugs.python.org fields: ```python activity = actor = 'jvickroy' assignee = 'none' closed = True closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'jvickroy' dependencies = [] files = [] hgrepos = [] issue_num = 523425 keywords = [] message_count = 5.0 messages = ['9445', '9446', '9447', '9448', '9449'] nosy_count = 3.0 nosy_names = ['brett.cannon', 'facundobatista', 'jvickroy'] pr_nums = [] priority = 'normal' resolution = 'fixed' stage = None status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue523425' versions = ['Python 2.2'] ```

4223e389-0246-440b-97cf-aa7e4eb01e0e commented 22 years ago

Below is a Python script that demonstrates a possible bug when using the shelve module for: Python 2.2 MS Windows 2000 and 98

For 10k, shelve entries, the script works as expected, but for 15k entries, an exception is raised after "some" number of updates.

I first tried to attach the script but received an error.

# begin script """ Demonstration of possible update bug using shelve module for: Python 2.2 MS Windows 2000 and 98 """

__author__ = 'jim.vickroy@noaa.gov'

import shelve

def keys():
   return [str(i) for i in range(100)]

def archive():
   return shelve.open('d:/logs/test')

##note = 'x'*10000 # this works 
note = 'x'*15000 # this fails with the following 
exception
"""
Traceback (most recent call last):
  File "C:\PYTHON22\lib\site-
packages\Pythonwin\pywin\framework\scriptutils.py", 
line 301, in RunScript
    exec codeObject in __main__.__dict__
  File "D:\py_trials\shelve_test.py", line 42, in ?
  File "D:\py_trials\shelve_test.py", line 23, in 
update
    db.close()
  File "C:\PYTHON22\lib\shelve.py", line 77, in 
__setitem__
    self.dict[key] = f.getvalue()
error: (0, 'Error')
"""

def update():
   db = archive()
   for this in keys():
      if db.has_key(this):
         entry = db[this]
         entry.append(note)
      else:
         entry = [note]
      db[this] = entry
   db.close()

def validate():
   db = archive()
   actual_keys = db.keys()
   expected_keys = keys()
   assert len(actual_keys) == len(expected_keys), \
      'expected %s -- got %s' % (len(expected_keys), 
len(actual_keys))
   for this in keys():
      entry = db[this]
      assert len(entry) == nbr_of_updates, \
             'expected %s -- got %s' % 
(nbr_of_updates, len(entry))
   db.close()

nbr_of_updates = 10
for i in range(nbr_of_updates):
   update()

validate()

# end script

brettcannon commented 21 years ago

Logged In: YES user_id=357491

I actually get a failure with 2.3b1 under OS X at the first assert:

Traceback (most recent call last):
  File "shelve_test.py", line 42, in ?
    validate() 
  File "shelve_test.py", line 30, in validate
    assert len(actual_keys) == len(expected_keys), 'expected %s -- got %s' % 
(len(expected_keys),  
AssertionError: expected 100 -- got 0
facundobatista commented 19 years ago

Logged In: YES user_id=752496

Please, could you verify if this problem persists in Python 2.3.4 or 2.4?

If yes, in which version? Can you provide a test case?

If the problem is solved, from which version?

Note that if you fail to answer in one month, I'll close this bug as "Won't fix".

Thank you!

. Facundo

facundobatista commented 19 years ago

Logged In: YES user_id=752496

Actually, the script you sent is not failing in the way you're saying. Seems to be another problem, probably in the script: I have to guess where ident it.

If you post another test case, could it please be more concise and attach it as a file to this bug?

Thank you!

4223e389-0246-440b-97cf-aa7e4eb01e0e commented 19 years ago

Logged In: YES user_id=17213

this bug does not appear in the following Python version:

'2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)]'