Skip to content

Commit 4721f11

Browse files
Make a new thread for each ros service call
1 parent c8d287c commit 4721f11

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/ros_tcp_endpoint/client.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,22 @@ def send_ros_service_request(self, srv_id, destination, data):
167167
# TODO: send a response to Unity anyway?
168168
return
169169
else:
170-
ros_communicator = self.tcp_server.source_destination_dict[
170+
ros_communicator = self.tcp_server.source_destination_dict[destination]
171+
service_thread = threading.Thread(target=self.service_call_thread, args=(srv_id, destination, data, ros_communicator))
172+
service_thread.daemon = True
173+
service_thread.start()
174+
175+
def service_call_thread(self, srv_id, destination, data, ros_communicator):
176+
response = ros_communicator.send(data)
177+
178+
if not response:
179+
error_msg = "No response data from service '{}'!".format(
171180
destination
172-
]
173-
response = ros_communicator.send(data)
174-
if not response:
175-
error_msg = "No response data from service '{}'!".format(
176-
destination
177-
)
178-
self.tcp_server.send_unity_error(error_msg)
179-
rospy.logerr(error_msg)
180-
# TODO: send a response to Unity anyway?
181-
return
181+
)
182+
self.tcp_server.send_unity_error(error_msg)
183+
rospy.logerr(error_msg)
184+
# TODO: send a response to Unity anyway?
185+
return
182186

183187
self.tcp_server.unity_tcp_sender.send_ros_service_response(srv_id, destination, response)
184188

0 commit comments

Comments
 (0)