Skip to content

Conversation

@ivanpauno
Copy link
Member

Needed by ros2/ros2cli#683.

I'm not sure if this is the ideal approach, maybe init()/shutdown() are doing too much (?).
I'm open to alternatives.

@ivanpauno ivanpauno added the enhancement New feature or request label Dec 22, 2021
@ivanpauno ivanpauno self-assigned this Dec 22, 2021
g_default_context = Context()
g_default_context.try_shutdown()
if not g_default_context.ok():
g_default_context = None
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish the default context registered an on_shutdown callback to manage the global variable too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently all the work is done with the default context lock taken.
If we register an on_shutdown() callback I don't think that would work.

Maybe it's possible to do that with some extra trick.

Signed-off-by: Ivan Santiago Paunovic <[email protected]>
@ivanpauno ivanpauno requested a review from sloretz December 22, 2021 18:38
Copy link
Contributor

@sloretz sloretz left a comment

Choose a reason for hiding this comment

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

LGTM with green CI

@ivanpauno
Copy link
Member Author

ivanpauno commented Dec 22, 2021

I had one extra issue related to #868 (comment) after doing some further testing.
The reset_executor() closure I was passing to on_shutdown() doesn't have any owner.
As Context only retains weak ownership of the callbacks being passed, it was sometimes not being called.

d65b487 fixes that.
After that change, Context retains week ownership of methods and shared ownership of free functions or closures.
I think that's intuitive.
I could also see the case of always retaining shared ownership and the user explictily passing a weak object when they need that, but that would be an unexpected change (particularly for methods).

@ivanpauno ivanpauno requested a review from sloretz December 22, 2021 19:01
self._callbacks.append(weakref.WeakMethod(callback, self._remove_callback))
else:
self._callbacks.append(weakref.ref(callback, self._remove_callback))
self._callbacks.append(callback)
Copy link
Contributor

Choose a reason for hiding this comment

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

I could also see the case of always retaining shared ownership and the user explictily passing a weak object when they need that, but that would be an unexpected change (particularly for methods).

Oh hmm. This is interesting. I don't see a better way, and it does seem like the behavior would be intuitive.

@ivanpauno
Copy link
Member Author

CI for this PR alone (I will rerun PR for ros2/ros2cli#683 after merging this one):

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

@ivanpauno ivanpauno merged commit 3f35f73 into master Dec 22, 2021
@delete-merged-branch delete-merged-branch bot deleted the ivanpauno/make-try-shutdonwn-behavior-match-shutdown branch December 22, 2021 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants