ros / ros_comm

ROS communications-related packages, including core client libraries (roscpp, rospy, roslisp) and graph introspection tools (rostopic, rosnode, rosservice, rosparam).
http://wiki.ros.org/ros_comm
747 stars 914 forks source link

python3.11 and roslogging (rospy.init_node) #2296

Open pepipho opened 1 year ago

pepipho commented 1 year ago

test.py

import rospy

print("initializing node")
rospy.init_node( 'listener' , anonymous = True )
print("done")

Expected behaviour: init ros node and print "Done". Current behaviour: python3.11 test.py is stucked in init_node method on this part rosgraph/roslogging.py

class RospyLogger(logging.getLoggerClass()):
    def findCaller(self, *args, **kwargs):
        """
        Find the stack frame of the caller so that we can note the source
        file name, line number, and function name with class name if possible.
        """
        file_name, lineno, func_name = super(RospyLogger, self).findCaller(*args, **kwargs)[:3]
        file_name = os.path.normcase(file_name)

        f = inspect.currentframe()
        if f is not None:
            f = f.f_back
        while hasattr(f, "f_code"):
            # Search for the right frame using the data already found by parent class.
            co = f.f_code
            filename = os.path.normcase(co.co_filename)
            if filename == file_name and f.f_lineno == lineno and co.co_name == func_name:
                break
            if f.f_back:
                f = f.f_back
pip show rospy
Name: rospy
Location: /opt/ros/noetic/lib/python3/dist-packages
Version: 1.15.11
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
Codename:       focal
destroy314 commented 1 year ago

Same question. For me, I just add break on the end of while hasattr(f, "f_code"):

jspricke commented 1 year ago

See https://github.com/ros/ros_comm/pull/2297/commits/685a96ec9cd67f1fd6f8cd52cce6f251f8899e67

Part of https://github.com/ros/ros_comm/pull/2297