From a533c59fdd41391b75130c1e365a96120d5bcde7 Mon Sep 17 00:00:00 2001 From: James Riehl Date: Wed, 11 Dec 2024 16:22:24 +0000 Subject: [PATCH] feat: add timeout to sync response --- python/docs/api/uagents/communication.md | 11 ----------- python/docs/api/uagents/context.md | 10 ++++++---- python/src/uagents/asgi.py | 6 ++++-- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/python/docs/api/uagents/communication.md b/python/docs/api/uagents/communication.md index e0a53273..8bd61b1a 100644 --- a/python/docs/api/uagents/communication.md +++ b/python/docs/api/uagents/communication.md @@ -80,17 +80,6 @@ Method to send an exchange envelope. Union[MsgStatus, Envelope]: Either the status of the message or the response envelope. - - -#### dispatch`_`sync`_`response`_`envelope - -```python -async def dispatch_sync_response_envelope( - env: Envelope) -> Union[MsgStatus, Envelope] -``` - -Dispatch a synchronous response envelope locally. - #### send`_`message`_`raw diff --git a/python/docs/api/uagents/context.md b/python/docs/api/uagents/context.md index 2a46794c..3a0bfad3 100644 --- a/python/docs/api/uagents/context.md +++ b/python/docs/api/uagents/context.md @@ -315,10 +315,12 @@ Please use the `ctx.agent.address` property instead. #### send ```python -async def send(destination: str, - message: Model, - sync: bool = False, - timeout: int = DEFAULT_ENVELOPE_TIMEOUT_SECONDS) -> MsgStatus +async def send( + destination: str, + message: Model, + sync: bool = False, + timeout: int = DEFAULT_ENVELOPE_TIMEOUT_SECONDS +) -> Union[MsgStatus, Envelope] ``` This is the pro-active send method which is used in on_event and diff --git a/python/src/uagents/asgi.py b/python/src/uagents/asgi.py index d3d14814..21c67240 100644 --- a/python/src/uagents/asgi.py +++ b/python/src/uagents/asgi.py @@ -18,7 +18,7 @@ from requests.structures import CaseInsensitiveDict from uagents.communication import enclose_response_raw -from uagents.config import RESPONSE_TIME_HINT_SECONDS +from uagents.config import DEFAULT_ENVELOPE_TIMEOUT_SECONDS, RESPONSE_TIME_HINT_SECONDS from uagents.context import ERROR_MESSAGE_DIGEST from uagents.crypto import is_user_address from uagents.dispatch import dispatcher @@ -361,7 +361,9 @@ async def __call__(self, scope, receive, send): # pylint: disable=too-many-bra # wait for any queries to be resolved if expects_response: - response_msg, schema_digest = await self._queries[env.sender] + response_msg, schema_digest = await asyncio.wait_for( + self._queries[env.sender], DEFAULT_ENVELOPE_TIMEOUT_SECONDS + ) if (env.expires is not None) and ( datetime.now() > datetime.fromtimestamp(env.expires) ):