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

Refactor client for multiple requests #170

Merged
merged 8 commits into from
Mar 27, 2018
Merged

Conversation

sloretz
Copy link
Contributor

@sloretz sloretz commented Jan 4, 2018

Opening a PR for feedback. This uses the Future class added in pull request #166 to allow simultaneous requests from the same client (part of #123). It is implemented like option 3 in this comment.

Specifically any ideas about call? This new version should not be called inside a callback because it would deadlock a SingleThreadedExecutor. It also is not very useful outside because an executor would need to be running in another thread for the client response to be taken from rcl.

CI

@sloretz sloretz self-assigned this Jan 4, 2018
@sloretz sloretz added the in progress Actively being worked on (Kanban column) label Jan 4, 2018
@sloretz sloretz force-pushed the rclpy_client_multiple_requests branch 2 times, most recently from 1182f65 to 6a7d6a9 Compare January 5, 2018 17:15
@sloretz sloretz force-pushed the rclpy_client_multiple_requests branch from 6a7d6a9 to 93bbea4 Compare January 18, 2018 21:06
@sloretz sloretz changed the base branch from rclpy_future_coroutine to master January 18, 2018 21:07
@sloretz sloretz changed the title [Seeking feedback] Refactor client for multiple requests Refactor client for multiple requests Jan 19, 2018
@sloretz sloretz force-pushed the rclpy_client_multiple_requests branch from ec14788 to f60ec40 Compare January 26, 2018 00:54
@sloretz sloretz added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jan 26, 2018
@mikaelarguedas
Copy link
Member

Mentioned it to @sloretz offline but writing it here for book-keeping.
This PR removes API used by various packages so we'll need to update those to use the new API and merge these PRs all together, of the top of my head: demo_nodes_py, examples_rclpy_* and ros2service need corresponding PRs

"""
sequence_number = _rclpy.rclpy_send_request(self.client_handle, req)
future = Future()
self._pending_requests[sequence_number] = future
Copy link
Member

Choose a reason for hiding this comment

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

In order to be defensive should this check / ensure that sequence_number is not already in the dictionary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added check in ece3781

future = Future()
self._pending_requests[sequence_number] = future

def remove_pending_request(future):
Copy link
Member

Choose a reason for hiding this comment

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

The argument isn't being used at the moment. Could this be a method on self instead and look up the to-be-deleted key based on the passed future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is bf87341 what you have in mind?

# The request was cancelled
pass
else:
future._set_executor(self)
Copy link
Member

Choose a reason for hiding this comment

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

It seems weird that the executor is calling a "private" method on the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideas? It seems weird to me too. The future needs a reference to an executor to be able to add callbacks.

asyncio solves the problem by expecting futures to be created via executor.create_future() which passes itself as a keyword argument to Future.__init__().

Right now the client doesn't have a reference to the executor, so rclpy can't do the same thing. Instead the client holds onto the future and hopes the user will add the node to an executor.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a suggestion as to how to change it, and I guess @dirk-thomas doesn't either?

So, I think it's ok to merge like this.

@sloretz sloretz added in progress Actively being worked on (Kanban column) and removed in review Waiting for review (Kanban column) labels Feb 1, 2018
@sloretz
Copy link
Contributor Author

sloretz commented Feb 7, 2018

CI including updates to other packages

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status
    • rclpy.test.test_timer.test_timer_number_callbacks100hertz Unrelated, though usually it's the 1khz timer test that is flaky not the 100hz test. Intereasting that the 100Hz failed while the 1Khz test passed

@sloretz sloretz added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Feb 9, 2018
@mikaelarguedas mikaelarguedas added this to the bouncy milestone Mar 1, 2018
Copy link
Member

@wjwwood wjwwood 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 some comments

# The request was cancelled
pass
else:
future._set_executor(self)
Copy link
Member

Choose a reason for hiding this comment

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

I don't have a suggestion as to how to change it, and I guess @dirk-thomas doesn't either?

So, I think it's ok to merge like this.

@@ -54,3 +54,14 @@ def spin(node):
executor.spin_once()
finally:
executor.shutdown()


def spin_until_future_complete(node, future):
Copy link
Member

Choose a reason for hiding this comment

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

Missing a doc block, but so are many existing functions. It would be nice to add, but not required I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in cf17f38

@sloretz
Copy link
Contributor Author

sloretz commented Mar 23, 2018

Running CI since it's been a while and cf17f38 was added.

Edit: CI looks good

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status (2 Composition test failures)

@sloretz sloretz merged commit 0c2ee4c into master Mar 27, 2018
@sloretz sloretz deleted the rclpy_client_multiple_requests branch March 27, 2018 00:56
@sloretz sloretz added in progress Actively being worked on (Kanban column) in review Waiting for review (Kanban column) and removed in review Waiting for review (Kanban column) in progress Actively being worked on (Kanban column) labels Mar 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in review Waiting for review (Kanban column)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants