Skip to content

Commit

Permalink
fix: add await to to_thread call (#3558)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ogabrielluiz authored Aug 26, 2024
1 parent c773d5c commit 60c586a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/backend/base/langflow/api/v1/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ async def build_vertices(
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

Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/services/tracing/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async def trace_context(
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)
Expand Down

0 comments on commit 60c586a

Please sign in to comment.