Retrieve error message from timer callback when using MultiThreadedExecutor
Hi,
I'm not getting proper error messages when I use a timer in combination with a MultiThreadedExecutor. Instead of crashing and displaying which line the error occurred I'm just getting The following exception was not retrieved...
Here is a minimal example:
import rclpy
from rclpy.node import Node
from rclpy.executors import MultiThreadedExecutor
class TimerNode(Node):
def __init__(self):
super().__init__('timer_test_node')
self.timer = self.create_timer(
0.1,
self.timer_callback,
)
def timer_callback(self):
print("Timer callback called")
variable
def main(*args, **kwargs):
rclpy.init(*args, **kwargs)
node = TimerNode(*args, **kwargs)
executor = MultiThreadedExecutor(num_threads=4)
executor.add_node(node)
executor.spin()
if __name__ == '__main__':
main()
Instead of crashing the following lines are repeated:
Timer callback called
The following exception was never retrieved: name 'variable' is not defined
Does anyone know how retrieve the exception and display the proper error message? It crashes as it should when using the default executor. It also crashes as it should when the error is not a timer callback function, i.e when called in a normal function.
The error message
...name 'variable' is not defined
totally makes sense. It should be eitherself.variable
orvariable = 1234 # something
. Right now, you are using this variable without defining it.@ravijoshi Thanks for your comment. However I know that my variable is not defined. It's not defined in order to crash the node. My problem is with how the error is displayed. I would something like this:
Since it is annoying to debug nodes when I can't see which line caused the error
Sorry, can you post a minimal reproducible example? It is difficult to understand what actually caused the error in the real case.
I think we misunderstand each other. My problem is not what is causing the errors. It's about how errors are displayed in the termimal when I have them. Currently errors are displayed as:
The following exception was never retrieved: name 'variable' is not defined
Instead of the normal error message like this:
File "/home/daniel/wl_meta_ws/build/timer_test/timer_test/timer_test.py", line 16, in timer_callback variable NameError: name 'variable' is not defined
The code used in the post is a minimal repriducible example of my issues with the error message format.