Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python 2.6: RuntimeError: dictionary changed size during iteration #62

Closed
kbandla opened this issue Jun 4, 2015 · 6 comments
Closed

Comments

@kbandla
Copy link
Owner

kbandla commented Jun 4, 2015

From y.dmi...@gmail.com on July 06, 2010 12:00:21

Python 2.6.5 (release26-maint, Jun 23 2010, 10:41:00)
[GCC 4.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import dpkt
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.6/site-packages/dpkt/init.py", line 24, in
import ethernet
File "/usr/lib/python2.6/site-packages/dpkt/ethernet.py", line 128, in
load_types()
File "/usr/lib/python2.6/site-packages/dpkt/ethernet.py", line 122, in __load_types
mod = __import
(modname, g)
File "/usr/lib/python2.6/site-packages/dpkt/ip6.py", line 95, in
import ip
File "/usr/lib/python2.6/site-packages/dpkt/ip.py", line 255, in
__load_protos()
File "/usr/lib/python2.6/site-packages/dpkt/ip.py", line 245, in __load_protos
for k, v in g.iteritems():
RuntimeError: dictionary changed size during iteration

Quick fix:
--- /usr/lib/python2.6/site-packages/dpkt/ip.py~ 2010-03-26 04:53:51.000000000 +0200
+++ /usr/lib/python2.6/site-packages/dpkt/ip.py 2010-07-06 18:54:05.013117134 +0300
@@ -242,7 +242,7 @@

XXX - auto-load IP dispatch table from IP_PROTO_* definitions

def __load_protos():
g = globals()

  • for k, v in g.iteritems():
  • for k, v in list(g.iteritems()):
    if k.startswith('IP_PROTO_'):
    name = k[9:].lower()
    try:

Original issue: http://code.google.com/p/dpkt/issues/detail?id=35

@kbandla
Copy link
Owner Author

kbandla commented Jun 4, 2015

From dugsong on January 06, 2011 07:45:41

I can't reproduce this?

@kbandla
Copy link
Owner Author

kbandla commented Jun 4, 2015

From jeggles...@gmail.com on March 01, 2011 13:13:25

I just ran into this on OS X.

[joe@deepwater-2:~]$ python -c 'import dpkt'
Traceback (most recent call last):
File "", line 1, in
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dpkt/init.py", line 24, in
import ethernet
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dpkt/ethernet.py", line 128, in
load_types()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dpkt/ethernet.py", line 122, in __load_types
mod = __import
(modname, g)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dpkt/ip6.py", line 95, in
import ip
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dpkt/ip.py", line 255, in
__load_protos()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dpkt/ip.py", line 245, in __load_protos
for k, v in g.iteritems():
RuntimeError: dictionary changed size during iteration

However, it's not consistent. Not sure what triggers it.

@kbandla
Copy link
Owner Author

kbandla commented Jun 4, 2015

From joed...@gmail.com on September 12, 2012 13:53:26

Alternate fix:

--- dpkt/ip.py ( revision 84 )
+++ dpkt/ip.py (working copy)
@@ -2,6 +2,7 @@

"""Internet Protocol."""

+import copy
import dpkt

class IP(dpkt.Packet):
@@ -241,7 +242,7 @@

XXX - auto-load IP dispatch table from IP_PROTO_* definitions

def __load_protos():

  • g = globals()
  • g = copy.copy(globals())
    for k, v in g.iteritems():
    if k.startswith('IP_PROTO_'):
    name = k[9:].lower()

@kbandla
Copy link
Owner Author

kbandla commented Jun 4, 2015

From dan...@lacoon.com on May 13, 2013 01:59:26

So I had the same problem and I dug in and I notice that the problem is that the import in that loop is not relative. Meaning that you might import a non-relevant package by accident (in my case mtp).

The solution is:
@@ -246,7 +246,7 @@
if k.startswith('IP_PROTO_'):
name = k[9:].lower()
try:

  •            mod = **import**(name, g)
    
  •            mod = **import**(name, g, level=1)
         except ImportError:
             continue
         IP.set_proto(v, getattr(mod, name.upper()))
    

This should be commited to head

@kbandla
Copy link
Owner Author

kbandla commented Jun 18, 2015

A quick glance makes #61 seem to be a related issue

@kbandla
Copy link
Owner Author

kbandla commented Aug 13, 2015

Fixed in d7684fe. Tracked in #203

@kbandla kbandla closed this as completed Aug 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant