From 5f4badfdbc84f54696170a47028e284074430629 Mon Sep 17 00:00:00 2001 From: Abhinav Tarigoppula Date: Fri, 29 May 2026 10:33:35 +0530 Subject: [PATCH] fix: replace deprecated `asyncio.get_event_loop()` with `get_running_loop()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `asyncio.get_event_loop()` is deprecated when there is no running event loop and emits a `DeprecationWarning` from Python 3.10 onwards. Both call sites in this fix are inside `async def` coroutines that are guaranteed to have a running loop, so `asyncio.get_running_loop()` is the correct replacement. Affected call sites: - `crewai/tools/structured_tool.py` — `CrewStructuredTool._arun` falls back to running a sync `self.func` in the executor. Also removed a redundant inline `import asyncio` since the module is already imported at the top of the file. - `crewai_tools/tools/snowflake_search_tool/snowflake_search_tool.py` — `SnowflakeSearchTool._get_connection` runs `self._create_connection` in the executor when no pooled connection is available. No behavior change. `run_in_executor` semantics are identical between the two loop accessors when a running loop is present; the only difference is the deprecation contract. --- .../tools/snowflake_search_tool/snowflake_search_tool.py | 2 +- lib/crewai/src/crewai/tools/structured_tool.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/crewai-tools/src/crewai_tools/tools/snowflake_search_tool/snowflake_search_tool.py b/lib/crewai-tools/src/crewai_tools/tools/snowflake_search_tool/snowflake_search_tool.py index fb293319c2..3ce4394a4b 100644 --- a/lib/crewai-tools/src/crewai_tools/tools/snowflake_search_tool/snowflake_search_tool.py +++ b/lib/crewai-tools/src/crewai_tools/tools/snowflake_search_tool/snowflake_search_tool.py @@ -166,7 +166,7 @@ async def _get_connection(self) -> SnowflakeConnection: with self._pool_lock: if self._connection_pool: return self._connection_pool.pop() - return await asyncio.get_event_loop().run_in_executor( + return await asyncio.get_running_loop().run_in_executor( self._thread_pool, self._create_connection ) diff --git a/lib/crewai/src/crewai/tools/structured_tool.py b/lib/crewai/src/crewai/tools/structured_tool.py index 6c24f52dcb..bed4d75eb7 100644 --- a/lib/crewai/src/crewai/tools/structured_tool.py +++ b/lib/crewai/src/crewai/tools/structured_tool.py @@ -261,9 +261,8 @@ async def ainvoke( try: if inspect.iscoroutinefunction(self.func): return await self.func(**parsed_args, **kwargs) - import asyncio - return await asyncio.get_event_loop().run_in_executor( + return await asyncio.get_running_loop().run_in_executor( None, lambda: self.func(**parsed_args, **kwargs) ) except Exception: