OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Cannot log in ROS2 node after building with cython

  • Thread starter Thread starter complikator
  • Start date Start date
C

complikator

Guest
I have ROS2 package written in python (with usage of rclpy) with ROS2 node. Inside this node I want to use node logger, lets say in following way:

Code:
def __init__(self):
    self.get_logger().info("Starting my node!")
    self.get_logger().warn("My node has already started!")

This works perfectly with standard python build, but when I want to build it using Cython (because code is going to production) I encounter error: Logger severity cannot be changed between calls. This is caused by implementation of CallerId:

Code:
class CallerId(
        namedtuple('CallerId', ['function_name', 'file_path', 'line_number', 'last_index'])):

    def __new__(cls, frame=None):
        if not frame:
            frame = _find_caller(inspect.currentframe())
        return super(CallerId, cls).__new__(
            cls,
            function_name=frame.f_code.co_name,
            file_path=os.path.abspath(inspect.getframeinfo(frame).filename),
            line_number=frame.f_lineno,
            last_index=frame.f_lasti,  # To distinguish between two callers on the same line
        )

in file rcutils_logger.py. I understand perfectly that after "cythonization" of file my inspect module won't work anymore (because every call to inspect functions returns same line/file), but I am unable to fix it. Has anyone encountered similar problems before?
<p>I have ROS2 package written in python (with usage of <code>rclpy</code>) with ROS2 node. Inside this node I want to use node logger, lets say in following way:</p>
<pre class="lang-py prettyprint-override"><code>def __init__(self):
self.get_logger().info("Starting my node!")
self.get_logger().warn("My node has already started!")
</code></pre>
<p>This works perfectly with standard python build, but when I want to build it using Cython (because code is going to production) I encounter error:
<code>Logger severity cannot be changed between calls.</code>
This is caused by implementation of <code>CallerId</code>:</p>
<pre class="lang-py prettyprint-override"><code>class CallerId(
namedtuple('CallerId', ['function_name', 'file_path', 'line_number', 'last_index'])):

def __new__(cls, frame=None):
if not frame:
frame = _find_caller(inspect.currentframe())
return super(CallerId, cls).__new__(
cls,
function_name=frame.f_code.co_name,
file_path=os.path.abspath(inspect.getframeinfo(frame).filename),
line_number=frame.f_lineno,
last_index=frame.f_lasti, # To distinguish between two callers on the same line
)
</code></pre>
<p>in file <code>rcutils_logger.py</code>. I understand perfectly that after "cythonization" of file my inspect module won't work anymore (because every call to inspect functions returns same line/file), but I am unable to fix it. Has anyone encountered similar problems before?</p>
 

Latest posts

D
Replies
0
Views
1
Damiano Miazzi
D
Top