Klauss++ - 2010-10-09

I'm also experiencing this.

Take a look at this experiment, it's interesting and might shed some light:

>>> from guppy import hpy
>>> hp = hpy()
>>> hp.heap()
Partition of a set of 23778 objects. Total size = 1760692 bytes.
Index Count % Size % Cumulative % Kind (class / dict of class)
0 10642 45 696652 40 696652 40 str
1 5432 23 196864 11 893516 51 tuple
2 345 1 112968 6 1006484 57 dict (no owner)
3 1546 7 105128 6 1111612 63 types.CodeType
4 66 0 104592 6 1216204 69 dict of module
5 174 1 93168 5 1309372 74 dict of type
6 194 1 86040 5 1395412 79 type
7 1472 6 82432 5 1477844 84 function
8 124 1 67552 4 1545396 88 dict of class
9 1027 4 36972 2 1582368 90 __builtin__.wrapper_descriptor
<86 more rows. Type e.g. '_.more' to view.>
>>> heap1 = hp.heap()
>>> heap1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/site-packages/guppy/heapy/UniSet.py", line 171, in __repr__
return self.fam.c_repr(self)
File "/usr/local/lib/python2.6/site-packages/guppy/heapy/UniSet.py", line 859, in c_repr
return self.c_str(a)
File "/usr/local/lib/python2.6/site-packages/guppy/heapy/UniSet.py", line 1616, in c_str
a.fam.get_partition(a).ppob(ob)
File "/usr/local/lib/python2.6/site-packages/guppy/heapy/UniSet.py", line 1704, in get_partition
p = a.fam.Part.partition(a, a.er)
File "/usr/local/lib/python2.6/site-packages/guppy/heapy/Part.py", line 774, in partition
return SetPartition(self, set, er)
File "/usr/local/lib/python2.6/site-packages/guppy/heapy/Part.py", line 705, in __init__
assert size == part.size
AssertionError
>>> hp.heap()
Partition of a set of 23785 objects. Total size = 1761700 bytes.
Index Count % Size % Cumulative % Kind (class / dict of class)
0 10644 45 696728 40 696728 40 str
1 5430 23 196808 11 893536 51 tuple
2 351 1 113784 6 1007320 57 dict (no owner)
3 1546 6 105128 6 1112448 63 types.CodeType
4 66 0 104592 6 1217040 69 dict of module
5 174 1 93168 5 1310208 74 dict of type
6 194 1 86040 5 1396248 79 type
7 1471 6 82376 5 1478624 84 function
8 124 1 67552 4 1546176 88 dict of class
9 1027 4 36972 2 1583148 90 __builtin__.wrapper_descriptor
<86 more rows. Type e.g. '_.more' to view.>
>>>

So, it seems the error is related to heap snapshots taken in the past (if you print it directly it doesn't show, it seems).

Could it be related to mutable objects? Perhaps the assertion is wrong, it doesn't consider the possibility of an item in the set growing after the snapshot was taken?

Just an idea.
No time to actually debug heapy, but whenever I have the time I might :)