CPython 2.7: Weakset data changing size during internal iteration

Temia Eszteri lamialily at cleverpun.com
Fri Jun 1 11:23:44 EDT 2012


I've got a bit of a problem - my project uses weak sets in multiple
areas, the problem case in particular being to indicate what objects
are using a particular texture, if any, so that its priority in OpenGL
can be adjusted to match at the same time as it being (de)referenced
by any explicit calls.

Problem is that for certain high-frequency operations, it seems
there's too much data going in and out for it to handle - the
following traceback is given to me (project path changed to protect
the innocent):

Traceback (most recent call last):
  File "C:\foo\bar\game.py", line 279, in update
    self.player.update()
  File "C:\foo\bar\player.py", line 87, in update
    PlayerBullet((self.x + 8, self.y + 9), 0, self.parent)
  File "C:\foo\bar\player.py", line 96, in __init__
    self.sprite = video.Sprite("testbullet", 0)
  File "C:\foo\bar\video.py", line 95, in __init__
    self.opengl_id = reference_texture(self, target)
  File "C:\foo\bar\video.py", line 310, in reference_texture
    if not video_handler.textures[target].references:
  File "C:\Python27\lib\_weakrefset.py", line 66, in __len__
    return sum(x() is not None for x in self.data)
  File "C:\Python27\lib\_weakrefset.py", line 66, in <genexpr>
    return sum(x() is not None for x in self.data)
RuntimeError: Set changed size during iteration

I can post the sources relevant to the traceback upon request, but
hopefully a traceback is sufficient as the most immediate problem is
in Python's libraries.

Any suggestions on what to do about this? I can't exactly throw a
.copy() in on top of the data iteration and call it good since it's
part of the standard Python library.

~Temia
--
When on earth, do as the earthlings do.



More information about the Python-list mailing list