Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feed.news.qwest.net!mpls-nntp-01.inet.qwest.net!news-out.octanews.net!indigo.octanews.net!auth.beige.octanews.com.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.python Subject: Re: set and dict iteration References: <7xy5le7cli.fsf@ruckus.brouhaha.com> <502D7E17.1070103@dejaviewphoto.com> Date: Thu, 16 Aug 2012 18:01:39 -0700 Message-ID: <7xvcgi8h70.fsf@ruckus.brouhaha.com> Organization: Nightsong/Fort GNOX User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:FNl7oH911tvnXFipq/dKyyaXb30= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Lines: 12 NNTP-Posting-Date: 16 Aug 2012 20:01:39 CDT X-Complaints-To: abuse@octanews.net Xref: csiph.com comp.lang.python:27216 Ian Kelly writes: > With regard to key insertion and deletion while iterating over a dict > or set, though, there is just no good reason to be doing that > (especially as the result is very implementation-specific), and I > wouldn't mind a more complete low-level check against it as long as > it's not too expensive (which is not clearly the case with the current > suggestion at all). One possible approach is to freeze the dictionary against modification while any iterator is open on it. You could keep a count of active iterators in the dict structure, adjusting it whenever an iterator is created or closed/destroyed.