Pass parameters to a service handler in rospy
In rospy
, message callbacks can have additional parameters, which allows me to write only one callback for different subscribers. For example:
def my_callback(msg, name):
rp.logwarn(name + "has received the message: " + msg)
subscribers = [
rp.Subscriber(
name+'/my_topic',
MyMessageType,
my_callback,
callback_args=name)
for name in "Alice Bob Carl David".split()]
works perfectly fine. However, the same is not possible for service handlers. For example:
def my_hanlder(request, name):
rp.logwarn(name + "has received the request: " + request)
providers = [
rp.Service(
name+'my_service',
MyServiceType,
my_handler,
handler_args=name)
for name in "Alice Bob Carl David".split()]
raises an error, because handler_args
is not a parameter of the constructor rp.Subscriber
.
How can I pass additional parameters to a service handler?