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

Docstring for rospy.on_shutdown() is wrong #651

Closed
opqdonut opened this issue Aug 20, 2015 · 5 comments

Comments

Projects
None yet
4 participants
@opqdonut
Copy link

commented Aug 20, 2015

The docstring claims that the hook should take no arguments, but in the "already shutdown" case the hook gets called with one argument.

The call is here:

h("already shutdown")

@spaghetti-

This comment has been minimized.

Copy link

commented Aug 24, 2015

I think we can just take out the argument. It is kind of difficult to work around this otherwise.

@wjwwood

This comment has been minimized.

Copy link
Member

commented Sep 1, 2015

@opqdonut I do not believe that is true. AFAIKT, those callbacks do take a string argument:

@opqdonut

This comment has been minimized.

Copy link
Author

commented Sep 2, 2015

the docstring for on_shutdown claims otherwise, as I said in my first comment :)

def on_shutdown(h):

@wjwwood

This comment has been minimized.

Copy link
Member

commented Sep 2, 2015

Probably related to this:

@dirk-thomas

This comment has been minimized.

Copy link
Member

commented Sep 17, 2015

The function client.py:on_shutdown() (

def on_shutdown(h):
"""
Register function to be called on shutdown. This function will be
called before Node begins teardown.
@param h: Function with zero args to be called on shutdown.
@type h: fn()
"""
rospy.core.add_client_shutdown_hook(h)
) registers a client shutdown function (
def add_client_shutdown_hook(h):
"""
Add client method to invoke when system shuts down. Unlike
L{add_shutdown_hook} and L{add_preshutdown_hooks}, these methods
will be called before any rospy internal shutdown code.
@param h: function with zero args
@type h: fn()
"""
_add_shutdown_hook(h, _client_shutdown_hooks)
).

Those are supposed to be always called without arguments:

for h in _client_shutdown_hooks:
try:
# client shutdown hooks do not accept a reason arg
h()

Therefore I would argue the current docstring is correct and does not need to be modified.

But when a callback is registered after shutdown it tries to pass an argument (

h("already shutdown")
). Therefore I would propose to not pass that argument if the function does not accept an argument. Please see #662 for the resulting patch.

If some of you could please try it in scenarios where it failed before that would be great to confirm that it works as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.