[Pythonmac-SIG] memory corruption Python 2.3/Mac OS 10.3?
Rayme Jernigan
rayme at pobox.com
Thu Aug 26 22:58:14 CEST 2004
Chris, thanks. I'm not using the weakref module, so I don't think so.
And as it happens, I've been directing the code to execute in the
terminal.
Bob, here's a somewhat minimized bit of code that illustrates the
problem. It won't make much sense, but it runs. The interesting part
occurs after the "While 1" loop is entered. I have a print statement to
flag that for you in the output, as well as before and after print
statements to bracket the area of apparent data corruption in
"list_of_lists." Thanks.
import random
maxnumberofdatacycles = 10
datacyclecount = 0
event = 0
class NetClass:
def __init__(self, inert, listsize, queuesize):
self.inert = inert
self.listsize = listsize
self.queuesize = queuesize
x = 0
# create a list for the list elements
self.list_of_lists = [ ]
node = [0,0,0,0,0,0,0]
# initialize the list with empty list elements
while x < self.listsize:
self.list_of_lists.append(node)
x += 1
# debug
print "Initialized self.list_of_lists = ", self.list_of_lists
def execute(self, event):
self.event = event
self.receiver = [0,0,0,0,0,0,0]
index = 0
# values to index lists data elements
data0 = 0
data1 = 1
data2 = 2
data3 = 3
data4 = 4
data5 = 5
# debug
print "Intering the execute method ", self.list_of_lists
# if this is a null event, return... youre done
if self.event == 0:
return (0,0)
# get the first receiver
self.receiver = self.list_of_lists[index]
while 1:
# debug
print "Entered 'While 1' loop ", self.list_of_lists
# is the data0 location zero?
if self.receiver[data0] == 0:
# debug
print "List of lists before operations on unrelated data",
self.list_of_lists
# store the datacyclecount in the data3 loocation of the
receiver
self.receiver[data3] = datacyclecount
# add the event to the data0 location in the receiver
self.receiver[data0] = self.event
# debug
print "List of lists after operations on unrelated data",
self.list_of_lists
# put this event in the result location in the receiver
self.receiver[data1] = self.event
del (self.receiver)
# return result
return (0,1)
class Generator:
def __init__(self, range):
self.range = self.series = range
self.state = 0
def observer(self):
if self.series == 0:
self.series = random.randrange(1,self.range)
if self.state == -1:
self.state = 1
elif self.state == 1:
self.state = -1
else:
self.state = 1
return self.state
else:
self.series -= 1
return 0
# create a data generator
system = Generator(10)
# create a network
net = NetClass(5,50,20)
while datacyclecount <= maxnumberofdatacycles:
# get new data
event = system.observer()
# send the event to the network and get a result back
result = net.execute(event)
# increment the data cycle counter
datacyclecount += 1
On Aug 26, 2004, at 2:51 PM, Bob Ippolito wrote:
>
> On Aug 26, 2004, at 2:03 PM, Rayme Jernigan wrote:
>
>> Hi All. I've been dealing with a nasty bug that looks a lot like
>> memory corruption in the version of Python that comes installed on OS
>> X 10.3.5.
>>
>> In short I have a list of lists that (without my telling it to) is
>> filling itself up with copies of a list element instance. The
>> instance value actually exists... it is defined elsewhere, and it's
>> later assigned to the zeroth element of the list, but it magically
>> gets assigned before I tell it to, and fills up the entire list to
>> boot. Judicious placement of print statements before and after some
>> operations on this list element which do not reference this "list of
>> lists" verify that this is what's happening. Arggh.
>
> Please post a minimal example that demonstrates this bug.
>
> -bob
>
>
William R Jernigan Associates
2616 Huntsman Trail
Zebulon, NC 27597
Phone: 919.269.0692
More information about the Pythonmac-SIG
mailing list