Python does not allow modifying a dictionary or list while iterating
over the elements.  The common idom to work around this is to create
a copy of the keys or elements and then use that information to delete
the corresponding entries from the original dictionary.

This patch changes the iteration to use an intermediate copy and then
modify the original dictionary.  This avoids the associated
RuntimeError.

Reported-by: Eelco Chaudron <[email protected]>
Reported-at: 
https://mail.openvswitch.org/pipermail/ovs-dev/2024-August/417000.html
Fixes: 14b4c575c284 ("utilities: a top like tool for ovs-dpctl dump-flows.")
Signed-off-by: Aaron Conole <[email protected]>
---
 utilities/ovs-dpctl-top.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utilities/ovs-dpctl-top.in b/utilities/ovs-dpctl-top.in
index 1708c2f374..f2d5bae6a6 100755
--- a/utilities/ovs-dpctl-top.in
+++ b/utilities/ovs-dpctl-top.in
@@ -1007,7 +1007,7 @@ class FlowDB:
     def decay(self, decayTimeInSeconds):
         """ Decay content. """
         now = datetime.datetime.now()
-        for (key, value) in self._flows.items():
+        for (key, value) in list(self._flows.items()):
             (stats_dict, updateTime) = value
             delta = now - updateTime
 
-- 
2.45.2

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to