Fix: Allow running in environments with existing event loop#222
Open
zhenliemao wants to merge 2 commits into
Open
Fix: Allow running in environments with existing event loop#222zhenliemao wants to merge 2 commits into
zhenliemao wants to merge 2 commits into
Conversation
Summary: This fix allows SkillSpector to run in environments that already have a running event loop, preventing RuntimeError when asyncio.run() is called from within an existing loop. Problem: When running SkillSpector in environments like: - Jupyter Notebooks - LangGraph Studio - FastAPI applications - Any programmatic usage within async code The call to asyncio.run() throws a RuntimeError: This event loop is already running and falls back to unfiltered static findings, silently disabling LLM analysis. The previous approach of detecting this state via error message substring matching is fragile and locale-dependent. Solution: 1. Add utility function in that properly detects running loops using 2. When no running loop exists, fall back to directly 3. When a loop is already running, offload execution to a separate thread with its own event loop via 4. Replace all calls across all analyzer nodes with the new helper 5. Remove unused asyncio imports from analyzer files Test: Add comprehensive unit tests for run_async covering: - Normal execution without existing running loop - Nested execution inside an already running loop - Exception propagation from async coroutines - Correct handling of async functions with await calls Signed-off-by: zhenliemao <494822673@qq.com>
Signed-off-by: zhenliemao <494822673@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
This fix allows SkillSpector to run in environments that already have a running event loop, preventing RuntimeError when asyncio.run() is called from within an existing loop.
Problem:
When running SkillSpector in environments like:
Solution:
Test:
Add comprehensive unit tests for run_async covering:
Fixes [BUG] RuntimeError: asyncio.run() called from within an already running event loop #108