[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Python3 errors due to list modificaion during iteration
commit 49c084d8388551804a84fb638db8db28acd0a0ef
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Tue Oct 17 03:55:01 2017 -0700
Python3 errors due to list modificaion during iteration
When iterating over keys python 2.x makes a shallow clone of lists whereas
python 3.x doesn't. Good for performance, but means we need to be careful about
modifying a list during iteration. Caught thanks to our integ tests...
======================================================================
ERROR: test_without_ephemeral_hidden_services
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/atagar/Desktop/stem/test/require.py", line 58, in wrapped
return func(self, *args, **kwargs)
File "/home/atagar/Desktop/stem/test/require.py", line 58, in wrapped
return func(self, *args, **kwargs)
File "/home/atagar/Desktop/stem/test/integ/control/controller.py", line 560, in test_without_ephemeral_hidden_services
self.assertEqual([], controller.list_ephemeral_hidden_services())
File "/home/atagar/Desktop/stem/stem/control.py", line 475, in wrapped
return func(self, *args, **kwargs)
File "/home/atagar/Desktop/stem/stem/control.py", line 2774, in list_ephemeral_hidden_services
result += self.get_info('onions/current').split('\n')
File "/home/atagar/Desktop/stem/stem/control.py", line 475, in wrapped
return func(self, *args, **kwargs)
File "/home/atagar/Desktop/stem/stem/control.py", line 1191, in get_info
self._set_cache(to_cache, 'getinfo')
File "/home/atagar/Desktop/stem/stem/control.py", line 3112, in _set_cache
for cache_key in self._request_cache.keys():
RuntimeError: dictionary changed size during iteration
---
stem/control.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/stem/control.py b/stem/control.py
index ce339da9..ac18c3bc 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -3109,7 +3109,7 @@ class Controller(BaseController):
# if no params are provided then clear the namespace
if not params and namespace:
- for cache_key in self._request_cache.keys():
+ for cache_key in list(self._request_cache.keys()):
if cache_key.startswith('%s.' % namespace):
del self._request_cache[cache_key]
@@ -3122,7 +3122,7 @@ class Controller(BaseController):
cache_key = key
if value is None:
- if cache_key in self._request_cache:
+ if cache_key in list(self._request_cache.keys()):
del self._request_cache[cache_key]
else:
self._request_cache[cache_key] = value
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits