Skip to content

Destroy listeners outside of spin_once() - #184

Closed
brawner wants to merge 1 commit into
crystal-develfrom
destroy_listeners
Closed

brawner wants to merge 1 commit into
crystal-develfrom
destroy_listeners

Conversation

@brawner

@brawner brawner commented Dec 15, 2018

Copy link
Copy Markdown
Contributor

Destroying subscriptions is not thread-safe. Because the executor spins the node in a separate QThread outside of the plugins UI threads, destroying listeners needs to happen after spin_once().

This adds a method for plugins to call that registers subscriptions and clients for destruction. Unfortunately this also means that the spinner object needs to be passed around.

This address issue #181

@brawner

brawner commented Dec 15, 2018

Copy link
Copy Markdown
Contributor Author

Here is an example using it:

ros-visualization/rqt_plot#20

@brawner

brawner commented Dec 18, 2018

Copy link
Copy Markdown
Contributor Author

@dirk-thomas @mlautman Ping for a review?

@mlautman mlautman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 after addressing 1 small comment

qDebug('Registering destruction for listener of type "{}"'.format(type(listener)))
self._listener_queue.put(listener)

def __destroy_listener__(self, listener):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this style? why not _destroy_listener?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because external functions should absolutely not call this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Prepending a single underscore (_) has some support for protecting module variables and functions (not included with from module import *). While prepending a double underscore (__ aka “dunder”) to an instance variable or method effectively makes the variable or method private to its class (using name mangling) we discourage its use as it impacts readability and testability and isn’t really private.

The trailing double underscores could go

self._abort = True
super().quit()

def register_listeners_for_destruction(self, *listeners):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This needs very prominent documentation. It is very reasonable for users to remove subscribers themselves if they don't know about this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Any suggestions? I imagine they will find rqt_gui crashing look at how other plugins do this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I really don't know. @dirk-thomas any ideas here? The issue we are having is that the spin method isn't thread safe and we are seeing segfaults when we try to unsubscribe while the executor is running.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Correction, spin is thread safe but destroying subscribers is not.

@brawner

brawner commented Jan 7, 2019

Copy link
Copy Markdown
Contributor Author

@dirk-thomas Any input on this PR and the accompanying rqt_plot PR?

ros-visualization/rqt_plot#20

@brawner

brawner commented Jan 8, 2019

Copy link
Copy Markdown
Contributor Author

rqt_topic also depends on this PR

@dirk-thomas

Copy link
Copy Markdown
Contributor

I don't think rqt should work around this by providing a difficult to discover API. Any Python application will have the same problem.

I think it would be better to improve the rclpy API to support this. Afaik rclcpp does allow you to use the API in that way.

@brawner

brawner commented Jan 9, 2019

Copy link
Copy Markdown
Contributor Author

It doesn't look like there has been any action on the related issue in rclpy I created. I can investigate the bug in rclpy and work on a PR.

@dirk-thomas

Copy link
Copy Markdown
Contributor

I can investigate the bug in rclpy and work on a PR.

That would be great!

@brawner

brawner commented Jan 12, 2019

Copy link
Copy Markdown
Contributor Author

Unfortunately, unless I had some very specific guidance, I don't think I can resolve the related Rclpy issue within our current rqt effort. It looks like it's related to this issue:

ros2/rclpy#192

https://github.com/brawner/rclpy/blob/test_destruction_outside_thread/rclpy/rclpy/executors.py#L29

@mlautman

Copy link
Copy Markdown
Member

Rather than wait indefinitely for the underlying bug to be fixed I think we should go ahead and merge this. Be sure to add comments explaining the spinner and noting that it can be removed once the related issues are closed

@dirk-thomas

Copy link
Copy Markdown
Contributor

We shouldn't merge this since it introduces API plugins would need to start using which they shouldn't need to once therclpy API has been update.

@mlautman
mlautman force-pushed the crystal-devel branch 2 times, most recently from 6ec4173 to e377071 Compare February 4, 2019 20:17
@dirk-thomas

Copy link
Copy Markdown
Contributor

The upstream rclpy ticket has been resolved. So this should be obsolete.

@dirk-thomas
dirk-thomas deleted the destroy_listeners branch April 25, 2019 19:14
@ghost ghost removed the in progress label Apr 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants