bug in my code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Duncan Smith

    bug in my code?

    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(iteration s):
    for i in range(iteration s):
    try:
    f = file('C:\\Pytho n22\\(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.p y", line 9, in test2
    dependencies, nodes = cPickle.load(f)
    cPickle.Unpickl ingError: 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







Working...