From a8a0c4812bd954cea99d75b6aafefeadc5d534fd Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Fri, 6 Dec 2024 11:28:50 +0100 Subject: [PATCH] rosnode: Fix unclosed socket in rosnode_ping command --- tools/rosnode/src/rosnode/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/rosnode/src/rosnode/__init__.py b/tools/rosnode/src/rosnode/__init__.py index 91b3e983b4..c6293e1634 100644 --- a/tools/rosnode/src/rosnode/__init__.py +++ b/tools/rosnode/src/rosnode/__init__.py @@ -359,6 +359,7 @@ def rosnode_ping(node_name, max_count=None, verbose=False, skip_cache=False): if verbose: print("node url has changed from [%s] to [%s], retrying to ping"%(node_api, new_node_api)) node_api = new_node_api + node.__exit__() node = ServerProxy(node_api) continue print("ERROR: connection refused to [%s]"%(node_api), file=sys.stderr) @@ -373,10 +374,12 @@ def rosnode_ping(node_name, max_count=None, verbose=False, skip_cache=False): time.sleep(1.0) except KeyboardInterrupt: pass - - if verbose and count > 1: - print("ping average: %fms"%(acc/count)) - return True + + if verbose and count > 1: + print("ping average: %fms"%(acc/count)) + return True + finally: + node.__exit__() def rosnode_ping_all(verbose=False, skip_cache=False): """