Repository navigation
Fix: <asyncio.locks.Semaphore object at 0xabcd [locked]> is bound to a different event loop - #15100
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR introduces ChangesLoop-Local Semaphore Implementation and Integration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
|
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@common/asyncio_utils.py`:
- Around line 33-42: Update the _get method in asyncio_utils.py to emit debug
logs for the semaphore lifecycle: log a debug message when you prune closed
event loop entries from self._semaphores (including which loop object was
removed) and log a debug message when you create a new per-loop semaphore
(including the loop and semaphore value). Use the module logger used elsewhere
in this file (e.g., logger = logging.getLogger(__name__)) to emit these messages
from the _get function so the actions are visible in debug traces.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: db38f9a7-8e79-4321-9819-5c894dce2a3f
📒 Files selected for processing (3)
common/asyncio_utils.pyrag/graphrag/utils.pyrag/svr/task_executor.py
| def _get(self) -> asyncio.Semaphore: | ||
| loop = asyncio.get_running_loop() | ||
| for cached_loop in list(self._semaphores): | ||
| if cached_loop.is_closed(): | ||
| self._semaphores.pop(cached_loop, None) | ||
| sem = self._semaphores.get(loop) | ||
| if sem is None: | ||
| sem = asyncio.Semaphore(self._value) | ||
| self._semaphores[loop] = sem | ||
| return sem |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Add debug logging for semaphore lifecycle in the new loop-local flow.
Please emit debug logs when closed-loop entries are pruned and when a new per-loop semaphore is created.
Proposed patch
import asyncio
+import logging
import weakref
+logger = logging.getLogger(__name__)
+
class LoopLocalSemaphore:
@@
def _get(self) -> asyncio.Semaphore:
loop = asyncio.get_running_loop()
for cached_loop in list(self._semaphores):
if cached_loop.is_closed():
self._semaphores.pop(cached_loop, None)
+ logger.debug("LoopLocalSemaphore pruned closed loop: loop_id=%s", id(cached_loop))
sem = self._semaphores.get(loop)
if sem is None:
sem = asyncio.Semaphore(self._value)
self._semaphores[loop] = sem
+ logger.debug("LoopLocalSemaphore created semaphore: loop_id=%s value=%d", id(loop), self._value)
return semAs per coding guidelines, **/*.py: Add logging for new flows.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def _get(self) -> asyncio.Semaphore: | |
| loop = asyncio.get_running_loop() | |
| for cached_loop in list(self._semaphores): | |
| if cached_loop.is_closed(): | |
| self._semaphores.pop(cached_loop, None) | |
| sem = self._semaphores.get(loop) | |
| if sem is None: | |
| sem = asyncio.Semaphore(self._value) | |
| self._semaphores[loop] = sem | |
| return sem | |
| import asyncio | |
| import logging | |
| import weakref | |
| logger = logging.getLogger(__name__) | |
| class LoopLocalSemaphore: | |
| def _get(self) -> asyncio.Semaphore: | |
| loop = asyncio.get_running_loop() | |
| for cached_loop in list(self._semaphores): | |
| if cached_loop.is_closed(): | |
| self._semaphores.pop(cached_loop, None) | |
| logger.debug("LoopLocalSemaphore pruned closed loop: loop_id=%s", id(cached_loop)) | |
| sem = self._semaphores.get(loop) | |
| if sem is None: | |
| sem = asyncio.Semaphore(self._value) | |
| self._semaphores[loop] = sem | |
| logger.debug("LoopLocalSemaphore created semaphore: loop_id=%s value=%d", id(loop), self._value) | |
| return sem |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@common/asyncio_utils.py` around lines 33 - 42, Update the _get method in
asyncio_utils.py to emit debug logs for the semaphore lifecycle: log a debug
message when you prune closed event loop entries from self._semaphores
(including which loop object was removed) and log a debug message when you
create a new per-loop semaphore (including the loop and semaphore value). Use
the module logger used elsewhere in this file (e.g., logger =
logging.getLogger(__name__)) to emit these messages from the _get function so
the actions are visible in debug traces.
a252bb1 to
440153c
Compare
…a different event loop
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15100 +/- ##
=======================================
Coverage 93.12% 93.12%
=======================================
Files 10 10
Lines 713 713
Branches 116 116
=======================================
Hits 664 664
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fix: <asyncio.locks.Semaphore object at 0xabcd [locked]> is bound to a different event loop