How to kill a subscription?

asked 2020-08-01 05:03:58 -0500

adry gravatar image

I' ve a fleet of robot that are handled by a scheduler. Its services are also to add or remove a node from the fleet. So, i've to remove the subscripion at its topics:

self.add_node = self.create_service(AddNode, '/scheduler/add_node', self.add_node_callback)
self.rem_node = self.create_service(RemNode, '/scheduler/rem_node', self.rem_node_callback)

self.subs ={}
self.f  = open("./src/scheduler/scheduler/Nodelist.txt", "r")
for node in nlist:
     self.subs[node] = self.create_subscription(Float64, '' + str(node) + '/battery_lvl', self.make_callback(node,'battery',self.msg_dictionary),10)

def rem_node_callback(self, request, response):
        if not( in self.msg_dictionary):
            response.response= + ' not exist'
            # self.f=open("./src/scheduler/scheduler/Nodelist.txt", "a+")
            # self.f.write("%s\n" % (
            # self.f.close()
            del self.subs[]
            del self.msg_dictionary[]

            response.response = + ' removed'
        return response

So if i have to remove a node, how to destroy the associated subscription?The issue is caused by the fact that maybe when i remove the key from subs, if make_callback is running, it no longer has a node to returning to

edit retag flag offensive close merge delete