bug in my code?

Duncan Smith buzzard at urubu.freeserve.co.uk
Mon Jul 14 21:28:09 EDT 2003


Greetings.  I am struggling to track down what I presume is a bug in my
code.  The trouble is that it only raises its head occasionally.  I have
managed to prune the code to the following:

shutTest.py
--------------------------------------------------------
import cPickle

def test2(iterations):
    for i in range(iterations):
        try:
            f = file('C:\\Python22\\(2, 2, 2, 3, 4).shu', 'r')
            try:
                dependencies, nodes = cPickle.load(f)
            finally:
                f.close()
        except IOError:
            pass
----------------------------------------------------------------

Calling the function with a suitable argument (say, 100) doesn't usually
pose a problem.  The file is opened OK and the data unpickled.  But
occasionally (or usually if I call the function with 1000 as argument) I get
the all too common, on Windows,

'The instruction at {some memory address} referenced memory at {some other
(and on one occasion the same) memory address}.  The memory could not be
"read".'

I just tried to run the function in the interactive window and got the
following traceback.

Traceback (most recent call last):
 File "<stdin>", line 1, in ?
 File "shutTest.py", line 9, in test2
  dependencies, nodes = cPickle.load(f)
cPickle.UnpicklingError: invalid load key, 'a'.

where the 'a' has a grave accent over it.

I'm guessing that the previous crashes have corrupted the file?  Is there
any reason why my code should have caused the crashes, or is this just
Windows 2000?  The crashes don't seem to be totally random as they always
occur in this section of code.  BTW I am using Python 2.2.2, and I had the
crashes in PythonWin, IDLE and the interactive window.  TIA.

Duncan











More information about the Python-list mailing list