Showing content from http://mail.python.org/pipermail/python-dev/attachments/20091011/d674ae2a/attachment.htm below:
<div class="gmail_quote">On Sun, Oct 11, 2009 at 10:50 AM, Antoine Pitrou <span dir="ltr"><<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
In py3k, the weak dict methods keys(), values() and items() have been<br>
changed to return iterators (they returned lists in 2.x).<br>
However, it turns out that it makes these methods quite fragile, because<br>
a GC collection can occur whenever during iterating, destroy one of the<br>
weakref'ed objects, and trigger a resizing of the underlying dict, which<br>
in turn raises an exception ("RuntimeError: dictionary changed size<br>
during iteration").<br></blockquote><div><br>Ouch! <br><br>The iterator from __iter__ is also affected.<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
1. Add the safe methods listkeys(), listitems(), listvalues() which would<br>
behave as the keys(), etc. methods from 2.x<br>
<br>
2. Make it so that keys(), items(), values() atomically build a list of<br>
items internally, which makes them more costly for large weak dicts, but<br>
robust.<br></blockquote></div><br>-1 on 1.<br>+0 on 2.<br><br>It'd be nice if we could postpone the resize if there are active iterators, but I don't think there's a clean way to track the iterators.<br><blockquote style="margin: 1.5em 0pt;">
--<br>
Daniel Stutzbach, Ph.D.<br>
President, <a href="http://stutzbachenterprises.com">Stutzbach Enterprises, LLC</a>
</blockquote>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4