fix: replace deprecated asyncio.get_event_loop() with get_running_loop()#5969
fix: replace deprecated asyncio.get_event_loop() with get_running_loop()#5969kratos0718 wants to merge 1 commit into
asyncio.get_event_loop() with get_running_loop()#5969Conversation
…loop()` `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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughTwo async methods are updated to use ChangesEvent loop accessor migration
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
asyncio.get_event_loop()is deprecated when there is no running event loop and emits aDeprecationWarningfrom Python 3.10 onwards. Per the official Python docs:Both call sites in this fix are inside
async defcoroutines that are guaranteed to have a running loop, soasyncio.get_running_loop()is the correct replacement.Affected call sites
crewai/tools/structured_tool.py—CrewStructuredTool._arunfalls back to running a syncself.funcin the executor when the function is not a coroutine. Also removed a redundant inlineimport asynciosince the module is already imported at the top of the file.crewai_tools/tools/snowflake_search_tool/snowflake_search_tool.py—SnowflakeSearchTool._get_connectionrunsself._create_connectionin the executor when no pooled connection is available.Behavior
No behavior change.
run_in_executorsemantics are identical between the two loop accessors when a running loop is present (which is the case in both contexts here, since both are insideasync defand the surrounding code already usesawait). The only difference is the deprecation contract.Note
I noticed this is the same pattern that was fixed in agno PR #8111 — keeping crewAI ready for Python versions that promote the warning to an error.
Summary by CodeRabbit