classification
Title: "RuntimeError: dictionary changed size during iteration" in Tkinter
Type: behavior Stage:
Components: Tkinter Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, christian.heimes, flox, gpolo, kbk, quentin.gallet-gilles, srid
Priority: normal Keywords: patch

Created on 2007-12-19 13:08 by quentin.gallet-gilles, last changed 2010-01-08 17:50 by flox. This issue is now closed.

Files
File name Uploaded Description Edit
tkinter_dictkeys.patch quentin.gallet-gilles, 2007-12-19 13:08
tkinter_issue1658.diff gpolo, 2008-05-30 02:14
Messages (8)
msg58805 - (view) Author: Quentin Gallet-Gilles (quentin.gallet-gilles) Date: 2007-12-19 13:08
While investigating for the stdlib reorg of Tkinter, I came across the
following error:

~/dev/py3k$ ./python Lib/lib-tk/Dialog.py 
Traceback (most recent call last):
  File "Lib/lib-tk/Dialog.py", line 45, in <module>
    Pack: {}})
  File "/home/quentin/dev/py3k/Lib/lib-tk/Tkinter.py", line 1996, in
__init__
    Widget.__init__(self, master, 'button', cnf, kw)
  File "/home/quentin/dev/py3k/Lib/lib-tk/Tkinter.py", line 1921, in
__init__
    for k in cnf.keys():
RuntimeError: dictionary changed size during iteration


The attached patch adds list() around the dict.keys() call.

On a related note, this doesn't appear to be an isolated error, since a
similar issue (#1649) was recently fixed in r59554. Would it be a good
idea to look for other identical cases ?
msg58815 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-19 17:48
Yes, it sounds like a good idea. The patch should be applied to 2.6.
msg67517 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-05-30 02:14
There is this same problem at scrolledtext.py (new name). I'm attaching
a patch that is a bit different that correct both cases.
msg72428 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-09-03 22:46
Can someone review the patch and apply please ? It is sad to leave
tkinter like this in py3k. Clearly there are not much people using it
there, but it is something very simple to fix.
msg72487 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-04 07:32
The patch is indeed simple.

A minor stylistic remark: instead of 
    for c in classes:
        del cnf[c[0]]
it would be clearer to write
    for k, v in classes:
        del cnf[v]
like the other loop does, 3 lines after.

Please apply.
msg72492 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-09-04 11:24
Committed r66215

I've applied this only in py3k since it doesn't affect python 2.6
msg97419 - (view) Author: Sridhar Ratnakumar (srid) Date: 2010-01-08 17:26
I get this error while running Python 2.6.4 tests (on 64-bit Linux box)

test_urllib
test test_urllib failed -- Traceback (most recent call last):
  File "/home/apy/rrun/tmp/autotest/apy/lib/python2.6/test/test_urllib.py", line 104, in setUp
    for k, v in os.environ.iteritems():
RuntimeError: dictionary changed size during iteration

Should open a new bug?
msg97422 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-01-08 17:50
> test_urllib
> test test_urllib failed -- Traceback (most recent call last):
>  File "/home/apy/rrun/tmp/autotest/apy/lib/python2.6/test/test_urllib.py", line 104, in setUp
>     for k, v in os.environ.iteritems():
> RuntimeError: dictionary changed size during iteration

I reopened issue7026 for this one.
History
Date User Action Args
2010-01-08 17:50:42floxsetnosy: + flox
messages: + msg97422
2010-01-08 17:26:15sridsetnosy: + srid
messages: + msg97419
2008-09-04 11:24:16gpolosetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg72492
versions: - Python 2.6
2008-09-04 07:32:36amaury.forgeotdarcsetkeywords: - needs review
nosy: + amaury.forgeotdarc
messages: + msg72487
2008-09-03 22:46:16gpolosetkeywords: + needs review
messages: + msg72428
2008-08-24 22:23:09nnorwitzsettype: crash -> behavior
2008-05-30 02:14:10gpolosetfiles: + tkinter_issue1658.diff
nosy: + gpolo
messages: + msg67517
2007-12-24 03:52:34kbksetnosy: + kbk
2007-12-19 17:48:07christian.heimessetversions: + Python 2.6
nosy: + christian.heimes
messages: + msg58815
priority: normal
keywords: + patch
resolution: accepted
2007-12-19 13:08:17quentin.gallet-gillescreate