rospy.subscripe does only work once when executed from script

asked 2018-05-15 09:15:03 -0500

master1991 gravatar image


i have a graphical interface which lets me stop and start a roscore and launchfiles. So far everything works fine on Bootup the roscore is started and the launchfile is launched. Then my interface will subscribe to topics that have been published to display them on screen. Now whenever i terminate the roscore and after start it again including the launch file the resubscribing to the published topics does not work anymore.

(Let me state here that what i try to do manually is EXACTLY what is done at bootup - Also if i disable the autoboot i still can start in manually once - Only second, third and so on time does not work.

I will provide u with the code that is executed (The parts that i believe are necessary - Feel free to ask for more):


def startCore(self):
        if not self.isCoreRunning():
            command = 'roscore'
            self.roscore = self.executeShellCommand(command)
            time.sleep(2)  # wait a bit to be sure the roscore is really launched


def launchEgmo(self):
        command = 'roslaunch ../launch/egmo.launch'
        if self.isCoreRunning() and not self.isLaunchfileRunning():
            self.roslaunch = self.executeShellCommand(command)

After an Instance of the Listener Class is generated (here is where the problem is hidden)

class Test(object):
def __init__(self):
    rospy.Subscriber('dps/combined',DpsCombined, self.callback)
    print("Init Test")

def callback(self,data):
    print("Callback Test")

Now this is what is done at bootup and also manually after stopping the core. When i try to restart it still prints my "Init Test" but no callback anymore. If i check using rosnode list, the node is not being generated!

Any idea? ( I am running kinetic on a raspberry pi and python 2.7)

Further code you might want to have a look at

def terminateCore(self):      
    # kill the nodes
    if self.isCoreRunning():
        global is_initialized

def executeShellCommand(self, command):
    command = shlex.split(command)
    return subprocess.Popen(command)
edit retag flag offensive close merge delete