CPython 2.7: Weakset data changing size during internal iteration

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Jun 1 23:05:01 EDT 2012


On Fri, 01 Jun 2012 08:23:44 -0700, Temia Eszteri wrote:

> 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

I doubt that very much. If you are using threads, it is more likely your 
code has a race condition where you are modifying a weak set at the same 
time another thread is trying to iterate over it (in this case, to 
determine it's length), and because it's a race condition, it only 
happens when conditions are *just right*. Since race conditions hitting 
are usually rare, you only notice it when there's a lot of data.



-- 
Steven



More information about the Python-list mailing list