-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Service clients freeze on multi-client cases.
Ref: ros2/rmw#372 Signed-off-by: Tomoya Fujita <[email protected]>
- Loading branch information
1 parent
1598c6b
commit e0e02a7
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import rclpy | ||
from rclpy.node import Node | ||
from example_interfaces.srv import AddTwoInts | ||
|
||
class MinimalClientAsync(Node): | ||
def __init__(self): | ||
super().__init__('minimal_client_async') | ||
self.cli = self.create_client(AddTwoInts, 'add_two_ints') | ||
while not self.cli.wait_for_service(timeout_sec=1.0): | ||
self.get_logger().info('service not available, waiting again...') | ||
|
||
def send_request(self, a, b): | ||
self.req = AddTwoInts.Request() | ||
self.req.a = a | ||
self.req.b = b | ||
self.future = self.cli.call_async(self.req) | ||
rclpy.spin_until_future_complete(self, self.future) | ||
return self.future.result() | ||
|
||
def main(args=None): | ||
rclpy.init(args=args) | ||
minimal_client = MinimalClientAsync() | ||
for i in range(1000000000): | ||
response = minimal_client.send_request(1, 2) | ||
if i%1000 == 0: | ||
minimal_client.get_logger().info( | ||
'Result of add_two_ints: for %d + %d = %d' % | ||
(1, 2, response.sum)) | ||
|
||
minimal_client.destroy_node() | ||
rclpy.shutdown() | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import rclpy | ||
from rclpy.node import Node | ||
from example_interfaces.srv import AddTwoInts | ||
|
||
class MinimalService(Node): | ||
def __init__(self): | ||
super().__init__('minimal_service') | ||
self.srv = self.create_service(AddTwoInts, 'add_two_ints', self.add_two_ints_callback) | ||
|
||
def add_two_ints_callback(self, request, response): | ||
response.sum = request.a + request.b | ||
return response | ||
|
||
def main(args=None): | ||
rclpy.init(args=args) | ||
minimal_service = MinimalService() | ||
rclpy.spin(minimal_service) | ||
rclpy.shutdown() | ||
|
||
if __name__ == '__main__': | ||
main() |