I had a problem with initializing a ROS node in python in a larger project. The following minimum reproducible example has the same issue:
#!/usr/bin/env python
import rospy
if __name__ == '__main__':
print("Init node")
rospy.init_node('testNode', anonymous=True)
print("Node initialized")
Only the "Init node" is printed, and the script freezes in the rospy.init_node() call.
roscore is already running, confirmed by rostopic list returning the /rosout topic.
I have tried reinstalling ros and all python packages, as well as rebuilding the ros project.
When debugging using pdb, the program is stuck in the following loop:
while hasattr(f, "f_code"):
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:
if f.f_back:
f = f.f_back
in the following path: */opt/ros/noetic/lib/python3/dist-packages/rosgraph/roslogging.py(64)findCaller() *
Any help would be greatly appreciated!
EDIT:
It is also not possible to ctrl + c to stop the process, and I have to close the terminal for it to stop.
If I comment out the call to logger.info("init_node, name[%s], pid[%s]", resolved_node_name, os.getpid())
which leads to the infinite loop as shown above, the program instead gets stuck in the following loop:
while not node.uri and not is_shutdown():
time.sleep(0.00001) #poll for XMLRPC init
in /opt/ros/noetic/lib/python3/dist-packages/rospy/impl/init.py(105)start_node()