fix: add await to to_thread call (#3558)

* refactor(tracing/service.py): change asyncio.create_task to self.logs_queue.put_nowait for better performance and readability

* fix(chat.py): remove unnecessary logging of exception in build_flow function to improve code readability and maintainability

* refactor(tracing/service.py): refactor _end_and_reset method to use asyncio.create_task for better performance and readability
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-08-26 18:53:24 -03:00 committed by GitHub
commit 60c586a52b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 3 deletions

View file

@ -329,8 +329,7 @@ async def build_flow(
build_task = asyncio.create_task(await asyncio.to_thread(_build_vertex, vertex_id, graph))
try:
await build_task
except asyncio.CancelledError as exc:
logger.exception(exc)
except asyncio.CancelledError:
build_task.cancel()
return

View file

@ -211,7 +211,7 @@ class TracingService(Service):
self._end_traces(trace_id, trace_name, e)
raise e
finally:
asyncio.create_task(asyncio.to_thread(self._end_and_reset, trace_id, trace_name, None))
asyncio.create_task(await asyncio.to_thread(self._end_and_reset, trace_id, trace_name, None))
async def _end_and_reset(self, trace_id: str, trace_name: str, error: Exception | None = None):
self._end_traces(trace_id, trace_name, error)