Skip to content

Commit

Permalink
Destroy parameter service clients
Browse files Browse the repository at this point in the history
  • Loading branch information
bjsowa committed Feb 11, 2025
1 parent 9b5e7d2 commit 62be848
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rosapi/src/rosapi/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ async def _set_param(node_name: str, name: str, value: str, parameter_type=None)
)

if not client.service_is_ready():
_node.destroy_client(client)
raise Exception(f"Service {client.srv_name} is not available")

request = SetParameters.Request()
Expand All @@ -137,6 +138,8 @@ async def _set_param(node_name: str, name: str, value: str, parameter_type=None)

await futures_wait_for(_node, [future], _timeout_sec)

_node.destroy_client(client)

if not future.done():
future.cancel()
raise Exception("Timeout occurred")
Expand Down Expand Up @@ -176,6 +179,7 @@ async def _get_param(node_name: str, name: str) -> ParameterValue:
)

if not client.service_is_ready():
_node.destroy_client(client)
raise Exception(f"Service {client.srv_name} is not available")

request = GetParameters.Request()
Expand All @@ -185,6 +189,8 @@ async def _get_param(node_name: str, name: str) -> ParameterValue:

await futures_wait_for(_node, [future], _timeout_sec)

_node.destroy_client(client)

if not future.done():
future.cancel()
raise Exception("Timeout occurred")
Expand Down Expand Up @@ -236,6 +242,7 @@ async def get_param_names(params_glob: str | None) -> list[str]:
nodes = [get_absolute_node_name(node) for node in get_nodes()]

futures: list[tuple[str, Future]] = []
clients = []
for node_name in nodes:
if node_name == _node.get_fully_qualified_name():
continue
Expand All @@ -248,11 +255,17 @@ async def get_param_names(params_glob: str | None) -> list[str]:
if client.service_is_ready():
future = client.call_async(ListParameters.Request())
futures.append((node_name, future))
clients.append(client)
else:
_node.destroy_client(client)

params = []

await futures_wait_for(_node, [future for _, future in futures], _timeout_sec)

for client in clients:
_node.destroy_client(client)

for node_name, future in futures:
if not future.done():
future.cancel()
Expand Down

0 comments on commit 62be848

Please sign in to comment.