Avoid RuntimeError caused by iteration over sys.modules

As is described in the doc[1], we should not iterate over sys.modules
directly because sys.modules can be changed during iterations.

[1] https://docs.python.org/3/library/sys.html#sys.modules

Change-Id: Iad4e19744ee78996728e44f3a1446c1c282ad437
This commit is contained in:
Takashi Kajinami
2023-11-10 18:28:56 +09:00
parent 3ccb56074c
commit c57f2cc6ff

View File

@@ -56,7 +56,7 @@ CLSNAME_ALIASES = {
('os_ken.lib.packet.ospf', 'StringifyMixin'): ''
}
for modname, moddef in sys.modules.items():
for modname, moddef in sys.modules.copy().items():
if not modname.startswith(PKT_LIB_PATH) or not moddef:
continue
for (clsname, clsdef, ) in inspect.getmembers(moddef):