use call_async in all service to avoid deadlock

This commit is contained in:
Junhan Chang
2025-08-13 04:25:51 +08:00
parent 0063df4cf3
commit a1538da39e
2 changed files with 8 additions and 6 deletions

View File

@@ -336,7 +336,7 @@ class BaseROS2DeviceNode(Node, Generic[T]):
res.response = ""
return res
def append_resource(req: SerialCommand_Request, res: SerialCommand_Response):
async def append_resource(req: SerialCommand_Request, res: SerialCommand_Response):
# 物料传输到对应的node节点
rclient = self.create_client(ResourceAdd, "/resources/add")
rclient.wait_for_service()
@@ -399,7 +399,7 @@ class BaseROS2DeviceNode(Node, Generic[T]):
logger.info(f"更新物料{container_query_dict['name']}的数据{resource['data']} dict")
else:
logger.info(f"更新物料{container_query_dict['name']}出现不支持的数据类型{type(resource)} {resource}")
response = rclient.call(request)
response = await rclient.call_async(request)
# 应该先add_resource了
res.response = "OK"
# 如果driver自己就有assign的方法那就使用driver自己的assign方法

View File

@@ -351,7 +351,7 @@ class HostNode(BaseROS2DeviceNode):
except Exception as e:
self.lab_logger().error(f"[Host Node] Failed to create ActionClient for {action_id}: {str(e)}")
def create_resource_detailed(
async def create_resource_detailed(
self,
resources: list[Union[list["Resource"], "Resource"]],
device_ids: list[str],
@@ -393,11 +393,11 @@ class HostNode(BaseROS2DeviceNode):
},
ensure_ascii=False,
)
response = sclient.call(request)
response = await sclient.call_async(request)
responses.append(response)
return responses
def create_resource(
async def create_resource(
self,
device_id: str,
res_id: str,
@@ -451,7 +451,9 @@ class HostNode(BaseROS2DeviceNode):
)
]
return self.create_resource_detailed(resources, device_ids, bind_parent_id, bind_location, other_calling_param)
response = await self.create_resource_detailed(resources, device_ids, bind_parent_id, bind_location, other_calling_param)
return response
def initialize_device(self, device_id: str, device_config: Dict[str, Any]) -> None:
"""