# Revision history [back]

### multiprocessing: rospy.init_node() has already been called

I have a python script which initializes a node through rospy.init_node() and in a later line it does the following:

robot2 = multiprocessing.Process(target=robot, kwargs={'robot_ip': ip2, 'uri': uri})
robot2.start()


which involves starting a new roscore with a new uri, changing the environmental variable by os.environ["ROS_MASTER_URI"] = "http://localhost:" + uri and initializing a new node with rospy.init_node(). However, for the second node the it gives the error that rospy.init_node() is already called.

My expectation however is that since the second node is made after in a seperate process, with separate roscore, and separate environmental variable, this error should not come.

An example similar to my code is the following:

class TheRobot(object):
def __init__(self,
robot_ip='172.16.1.2',
**kwargs):

self.uri  = str(uri)
os.environ["ROS_MASTER_URI"] = "http://localhost:" + self.uri
venv = os.environ.copy()
self.roscore_proc = subprocess.Popen(["roscore", '-p', self.uri],
stdout=None,
stderr=sys.stderr,
preexec_fn=os.setsid
)
rospy.init_node('robot_setup_node_{}'.format(self.uri))

class DoubleRobot(TheRobot):
def __init__(self,
ip1='172.16.0.2',
ip2='172.16.1.2',
uri=None,
**kwargs):

super().__init__(robot_ip=ip1, uri=uri)
robot2 = multiprocessing.Process(target=TheRobot, kwargs={'robot_ip': ip2, 'uri': uri+1})
robot2.start()

twin_panda = DoubleRobot(ip1='172.16.0.2', ip2='172.16.1.2', uri=11314)


### multiprocessing: rospy.init_node() has already been called

I have a python script which initializes a node through rospy.init_node() and in a later line it does the following:

robot2 = multiprocessing.Process(target=robot, kwargs={'robot_ip': ip2, 'uri': uri})
robot2.start()


which involves starting a new roscore with a new uri, changing the environmental variable by os.environ["ROS_MASTER_URI"] = "http://localhost:" + uri and initializing a new node with rospy.init_node(). However, for the second node the it gives the error that rospy.init_node() is already called.

My expectation however is that since the second node is made after in a seperate process, with separate roscore, and separate environmental variable, this error should not come.

An example similar to my code is the following:

class TheRobot(object):
def __init__(self,
robot_ip='172.16.1.2',
**kwargs):

self.uri  = str(uri)
os.environ["ROS_MASTER_URI"] = "http://localhost:" + self.uri
venv = os.environ.copy()
self.roscore_proc = subprocess.Popen(["roscore", '-p', self.uri],
stdout=None,
stderr=sys.stderr,
preexec_fn=os.setsid
)
rospy.init_node('robot_setup_node_{}'.format(self.uri))

class DoubleRobot(TheRobot):
def __init__(self,
ip1='172.16.0.2',
ip2='172.16.1.2',
uri=None,
**kwargs):

super().__init__(robot_ip=ip1, uri=uri)
robot2 = multiprocessing.Process(target=TheRobot, kwargs={'robot_ip': ip2, 'uri': uri+1})
robot2.start()

twin_panda = DoubleRobot(ip1='172.16.0.2', ip2='172.16.1.2', uri=11314)


a similar question but without multiprocessing can be found [here] (https://answers.ros.org/question/204067/rospyinit_node-has-already-been-called-with-different-arguments/). but it did not help. In general,I'd be grateful for any suggestion for the above purpose, or for any other alternative.

### multiprocessing: rospy.init_node() has already been called

I have a python script which initializes a node through rospy.init_node() and in a later line it does the following:

robot2 = multiprocessing.Process(target=robot, kwargs={'robot_ip': ip2, 'uri': uri})
robot2.start()


which involves starting a new roscore with a new uri, changing the environmental variable by os.environ["ROS_MASTER_URI"] = "http://localhost:" + uri and initializing a new node with rospy.init_node(). However, for the second node the it gives the error that rospy.init_node() is already called.

My expectation however is that since the second node is made after in a seperate process, with separate roscore, and separate environmental variable, this error should not come.

An example similar to my code is the following:

class TheRobot(object):
def __init__(self,
robot_ip='172.16.1.2',
**kwargs):

self.uri  = str(uri)
os.environ["ROS_MASTER_URI"] = "http://localhost:" + self.uri
venv = os.environ.copy()
self.roscore_proc = subprocess.Popen(["roscore", '-p', self.uri],
stdout=None,
stderr=sys.stderr,
preexec_fn=os.setsid
)
rospy.init_node('robot_setup_node_{}'.format(self.uri))

class DoubleRobot(TheRobot):
def __init__(self,
ip1='172.16.0.2',
ip2='172.16.1.2',
uri=None,
**kwargs):

super().__init__(robot_ip=ip1, uri=uri)
robot2 = multiprocessing.Process(target=TheRobot, kwargs={'robot_ip': ip2, 'uri': uri+1})
robot2.start()

twin_panda = DoubleRobot(ip1='172.16.0.2', ip2='172.16.1.2', uri=11314)


a similar question but without multiprocessing can be found [here] (https://answers.ros.org/question/204067/rospyinit_node-has-already-been-called-with-different-arguments/). here but it did not help. In general,I'd be grateful for any suggestion for the above purpose, or for any other alternative.