Skip to content

Reconnection after closing leads to --> RosTimeoutError("Failed to connect to ROS") #121

@CristianGariboldi

Description

@CristianGariboldi

Description
I am using roslibpy to connect a python simulator with ros2 environment. In the simulator there are different scenarios with the duration of 15 seconds each, with a frequency of 10 Hz. So, when you iterate over the scenarios for visualization purposes, you can understand at which point of the simulation of a scenario you are by reading the variable self._iteration.
When self._iteration == 0, I start the connection with roslibpy. When self._iteration == 148 I close the connection and I set the ros related function to None, otherwise I get some problems with the simulator.
Now, since the next scenario is going to begin, self._iteration is set again to zero and according to my script, I should start a new connection with roslibpy, but instead I get the error:

raise RosTimeoutError("Failed to connect to ROS")
roslibpy.core.RosTimeoutError: Failed to connect to ROS

To Reproduce
I cannot provide the entire code of the simulation, but the connection and disconnection script is the following:

def __init__():
    self.client_traj = None

def connection():

    if self._iteration < 148:
          if (self.client_traj is None or not self.client_traj.is_connected):
              time.sleep(1)
              self.client_traj = Ros(host='localhost', port=9090)
              self.client_traj.connect()
              self.client_traj.run()
              
    elif self._iteration >= 148:
                self.client_traj.close()
                self.client_traj = None
                time.sleep(1)

Expected behavior
It should be able to connect. Indeed, when I run the simulator, in the first scenario it can connect without any problems, but for the second scenario, it fails.

System (please complete the following information):

  • OS: Linux
  • Python version 3.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions