Open GoogleCodeExporter opened 9 years ago
I can't reproduce this?
Original comment by dugsong
on 6 Jan 2011 at 3:45
I just ran into this on OS X.
[joe@deepwater-2:~]$ python -c 'import dpkt'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dpkt/__init__.py", line 24, in <module>
import ethernet
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dpkt/ethernet.py", line 128, in <module>
__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 <module>
import ip
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dpkt/ip.py", line 255, in <module>
__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.
Original comment by jeggles...@gmail.com
on 1 Mar 2011 at 9:13
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()
Original comment by joed...@gmail.com
on 12 Sep 2012 at 8:53
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
Original comment by dan...@lacoon.com
on 13 May 2013 at 8:59
Original issue reported on code.google.com by
y.dmi...@gmail.com
on 6 Jul 2010 at 4:00