Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timeout option for ros2param to find node. #802

Merged
merged 3 commits into from
Feb 24, 2023

Conversation

fujitatomoya
Copy link
Collaborator

address #799

Signed-off-by: Tomoya Fujita Tomoya.Fujita@sony.com

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
@fujitatomoya
Copy link
Collaborator Author

@audrow @gbiggs what do you think? I will add timeout option to other ros2 param sub-command as well.

@fujitatomoya
Copy link
Collaborator Author

@iuhilnehc-ynos it would be helpful if you can review.

Copy link

@iuhilnehc-ynos iuhilnehc-ynos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use

def wait_for(predicate, timeout, period=0.1):
instead of adding wait_for_node?
and then use it similar to
def daemon_ready():
try:
pickler.dump(None)
return False
except OSError:
return True
if not wait_for(daemon_ready, timeout):
.

Just a tiny minor suggestion.

@iuhilnehc-ynos
Copy link

iuhilnehc-ynos commented Feb 8, 2023

If the wait_for_node is a helper code that will be used in somewhere else, what about using wait_for in the wait_for_node?

def wait_for_node(node, node_name, include_hidden_nodes=False, timeout=1.0) -> bool:
    def check_node_names():
        node_names = get_node_names(
            node=node, include_hidden_nodes=include_hidden_nodes)
        return True if node_name in {n.full_name for n in node_names} else False

    return wait_for(check_node_names, timeout)

@iuhilnehc-ynos
Copy link

iuhilnehc-ynos commented Feb 8, 2023

BTW:

while not predicate():
if time.time() > deadline:
break
time.sleep(period)
return predicate()

should be updated, because the predicate() is unnecessary to be called twice under some situations.
(It reminded me of the logic similar to https://github.com/gcc-mirror/gcc/blob/83ffe9cde7fe0b4deb0d1b54175fd9b19c38179c/libstdc%2B%2B-v3/include/std/condition_variable#L348-L351.)

    while not predicate():
        if time.time() > deadline:
            return predicate()
        time.sleep(period)
    return True

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
@fujitatomoya
Copy link
Collaborator Author

@iuhilnehc-ynos thanks for the suggested fix, all addressed in 776312d

@fujitatomoya
Copy link
Collaborator Author

I believe that same option can be applied at lease ros2param sub command, since other sub commands have possibly same problem.

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
@fujitatomoya
Copy link
Collaborator Author

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@fujitatomoya
Copy link
Collaborator Author

  • Linux-aarch64 Build Status

@fujitatomoya
Copy link
Collaborator Author

@audrow @gbiggs friendly ping, requesting another review.

Copy link

@destogl destogl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for following up on this!

I have just a small proposal to increase the default timeout. As you see in the tests, 1, second could be too low.

ros2param/ros2param/verb/describe.py Show resolved Hide resolved
Copy link
Member

@audrow audrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - thanks, @fujitatomoya!

@fujitatomoya
Copy link
Collaborator Author

@audrow thanks for the review, i will go ahead to merge this.

@fujitatomoya fujitatomoya merged commit f31cd91 into rolling Feb 24, 2023
@delete-merged-branch delete-merged-branch bot deleted the fujitatomoya/20230207-ros2param-timeout branch February 24, 2023 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants