-
Notifications
You must be signed in to change notification settings - Fork 278
Description
Bug report
Required Info:
- Operating System:
- Ubuntu 20.04
- Installation type:
- Binary
- Version or commit hash:
- Foxy
- DDS implementation:
- Cyclone
- Client library (if applicable):
- rclpy
Steps to reproduce issue
import rclpy
async def throwing_task():
raise FileNotFoundError()
async def test_1():
try:
await throwing_task()
except FileNotFoundError:
pass
return True
async def test_2(executor):
task = executor.create_task(throwing_task)
try:
await task
except FileNotFoundError:
print("Error but should keep going")
return True
rclpy.init()
node = rclpy.create_node("test_wait")
executor = rclpy.get_global_executor()
executor.add_node(node)
task = executor.create_task(test_1)
executor.spin_until_future_complete(task)
assert task.result()
task = executor.create_task(test_2, executor)
executor.spin_until_future_complete(task)
assert task.result()
rclpy.shutdown()Expected behavior
The above code should complete and pass since the FileNotFoundError is caught in both cases
Actual behavior
The executor itself raises an exception on test_2 which is uncaught and brings down the entire test...
Additional information
I was trying to run a number of async callbacks in the rclpy executor, and I was raising exceptions in some cases. For some reason, those would bring down the entire node. I tracked it down to these lines:
rclpy/rclpy/rclpy/executors.py
Line 724 in f6d652f
| if handler.exception() is not None: |
I am not sure why the executor is raising the exception of the task 🤔 It might be due to the fact that subscribers, timers etc... are tasks that are never explicitly awaited? I don't have much knowledge about the internals of rclpy but this is very surprising coming from asyncio... It is also very surprising to see that the exception is only improperly raised when packaged as an asynchronous task, and not when awaited directly.
Thank you!