Repository navigation
Replace deprecated asyncio.get_event_loop() with asyncio.get_running_loop() in coroutine contexts - #8914
Replace deprecated asyncio.get_event_loop() with asyncio.get_running_loop() in coroutine contexts#8914LVsarff wants to merge 1 commit into
Conversation
…loop() in coroutine contexts
Strix Security Review✅ No open security findings. PR summary: Replaces three deprecated asyncio.get_event_loop() calls in lib/crewai with asyncio.get_running_loop() at sites that always execute inside a coroutine. Review summaryThis PR makes three one-line, behavior-equivalent replacements of Ruled out (1)
Review 1 on this PR · Reviewed by Strix |
Summary
asyncio.get_event_loop()is deprecated since Python 3.12 (and raisesRuntimeErrorin Python 3.14 when no current loop exists). In coroutine contexts the recommended replacement isasyncio.get_running_loop(), which returns exactly the same loop with no deprecation.This PR replaces the three usages in
lib/crewaithat are always executed inside a running event loop:src/crewai/tools/structured_tool.py— insideasync def _arun, so a loop is always runningsrc/crewai/rag/chromadb/client.py— insideasync def _alocked, so a loop is always runningsrc/crewai/utilities/streaming.py— theuse_async=Truebranch ofcreate_streaming_state, which is only reached from async kickoff paths (Crew.kickoff_async/ streaming kickoff), so a loop is always runningChanges
One-line, behavior-identical replacement of
asyncio.get_event_loop()withasyncio.get_running_loop()in each of the three files above.Verification
py_compilepasses for all three filesruff check --no-fixreports no new findings on the changed lines (existing findings in these files are pre-existing and untouched)get_running_loop()returns the same loopget_event_loop()wouldFixes #8912
Note: this PR supersedes #8910, which was submitted without an issue reference and auto-closed by the first-time-contributor gate as a result (reopen is not permitted for external contributors).
LLM disclosure
This change was prepared with the assistance of an AI coding agent and reviewed before submission. Per the repository's contribution guidelines, please add the
llm-generatedlabel to this PR if appropriate (I don't have permission to add labels myself).Note
Low Risk
Mechanical asyncio API update with no intended behavior change; each site is already inside a running coroutine.
Overview
Replaces deprecated
asyncio.get_event_loop()withasyncio.get_running_loop()in threelib/crewaicall sites that always run inside an active event loop, avoiding Python 3.12+ deprecation warnings and Python 3.14 failures when no default loop exists.The swap is one line each in ChromaDB async locking (
_alocked), sync tool execution fromainvokeviarun_in_executor, and async streaming setup whencreate_streaming_state(use_async=True)(and the same pattern already used in frame streaming). Runtime behavior should be unchanged: the running loop is the same object the old API would return in these paths.Reviewed by Cursor Bugbot for commit 20d369f. Bugbot is set up for automated code reviews on this repo. Configure here.