bug in my code?

D

Duncan Smith

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top