How to kill a subscription?
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.msg_dictionary={}
self.subs ={}
self.f = open("./src/scheduler/scheduler/Nodelist.txt", "r")
nlist= self.f.read().splitlines()
self.f.close()
for node in nlist:
self.msg_dictionary[node]={'battery':0.00}
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(request.name in self.msg_dictionary):
response.response= request.name + ' not exist'
else:
# self.f=open("./src/scheduler/scheduler/Nodelist.txt", "a+")
# self.f.write("%s\n" % (request.name))
# self.f.close()
del self.subs[request.name]
del self.msg_dictionary[request.name]
response.response = request.name + ' 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