Disconnecting the connection with index=0 makes no sense when there are more than one connections, as the list "rotates around" and populates index 0 after del.
Just disconnect all NodeConns in any case.
Disconnecting the connection with index=0 makes no sense when there are more than one connections, as the list "rotates around" and populates index 0 after del.
Just disconnect all NodeConns in any case.
53 | @@ -54,7 +54,7 @@ def run_test(self): 54 | # p2p_conns[2] will test resetting the counters 55 | p2p_conns = [] 56 | 57 | - for i in range(3): 58 | + for _ in range(3):
Interested in the use of the underscore as the variable name here, did some reading and from what I've read use of the underscore only works as something other than a variable name when used in an interactive python shell? Other than that people seem to believe it's a bad naming convention.
Context: https://stackoverflow.com/questions/26895362/what-does-in-python-do
_ as a variable name in python is a convention to indicate that the result won't be used.
Thanks for the explanation, makes sense.
191 | - del self.p2ps[index] 192 | + def disconnect_p2ps(self): 193 | + """Close all p2p connections to the node.""" 194 | + for _ in range(len(self.p2ps)): 195 | + index = 0 196 | + # Connection could have already been closed by other end.
Is the order of deletion relevant? If not, something like this is both easier to read and likely more efficient:
for x in self.p2ps:
if x.connection is not None:
x.connection.disconnect_node()
self.p2ps = []
No, the order is not relevant. Will switch to your suggestion. (I tried to minimize the --ignore-all-space diff)
utACK faaa7db