|
30 | 30 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
31 | 31 | # POSSIBILITY OF SUCH DAMAGE. |
32 | 32 |
|
33 | | -from threading import Condition, Thread |
| 33 | +from threading import Event, Thread |
34 | 34 | from typing import Any, Callable, Optional |
35 | 35 |
|
36 | 36 | from rclpy.callback_groups import ReentrantCallbackGroup |
@@ -155,30 +155,27 @@ def call_service( |
155 | 155 | raise InvalidServiceException(service) |
156 | 156 |
|
157 | 157 | future = client.call_async(inst) |
158 | | - condition = Condition() |
| 158 | + event = Event() |
159 | 159 |
|
160 | 160 | def future_done_callback(): |
161 | | - with condition: |
162 | | - condition.notify_all() |
| 161 | + event.set() |
163 | 162 |
|
164 | | - future.add_done_callback(lambda future: future_done_callback()) |
| 163 | + future.add_done_callback(lambda _: future_done_callback()) |
165 | 164 |
|
166 | | - with condition: |
167 | | - if not condition.wait_for( |
168 | | - lambda: future.done(), |
169 | | - timeout=(server_response_timeout if server_response_timeout > 0 else None), |
170 | | - ): |
171 | | - future.cancel() |
172 | | - node_handle.destroy_client(client) |
173 | | - raise Exception("Timeout exceeded while waiting for service response") |
| 165 | + if not event.wait(timeout=(server_response_timeout if server_response_timeout > 0 else None)): |
| 166 | + future.cancel() |
| 167 | + node_handle.destroy_client(client) |
| 168 | + raise Exception("Timeout exceeded while waiting for service response") |
| 169 | + |
| 170 | + node_handle.destroy_client(client) |
174 | 171 |
|
175 | 172 | result = future.result() |
176 | 173 |
|
177 | | - node_handle.destroy_client(client) |
178 | 174 | if result is not None: |
179 | 175 | # Turn the response into JSON and pass to the callback |
180 | 176 | json_response = extract_values(result) |
181 | 177 | else: |
182 | | - raise Exception("Service call returned None") |
| 178 | + exception = future.exception() |
| 179 | + raise Exception("Service call exception: " + str(exception)) |
183 | 180 |
|
184 | 181 | return json_response |
0 commit comments