Skip to content

Commit db50447

Browse files
phernandezclaude
andcommitted
fix: use SelectorEventLoop on Windows to avoid cleanup errors
The Windows ProactorEventLoop can raise "IndexError: pop from an empty deque" during event loop cleanup when there are pending handles. This was causing the test_bm_tool_help_exits_cleanly test to fail on Windows. Switch to WindowsSelectorEventLoopPolicy on Windows since we don't need ProactorEventLoop's features (subprocess pipes, named pipes) for CLI initialization. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
1 parent c3b5981 commit db50447

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/basic_memory/services/initialization.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import asyncio
88
import os
9+
import sys
910
from pathlib import Path
1011

1112

@@ -193,5 +194,12 @@ async def _init_and_cleanup():
193194
# Always cleanup database connections to prevent process hang
194195
await db.shutdown_db()
195196

197+
# On Windows, use SelectorEventLoop to avoid ProactorEventLoop cleanup issues
198+
# The ProactorEventLoop can raise "IndexError: pop from an empty deque" during
199+
# event loop cleanup when there are pending handles. SelectorEventLoop is more
200+
# stable for our use case (no subprocess pipes or named pipes needed).
201+
if sys.platform == "win32":
202+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
203+
196204
asyncio.run(_init_and_cleanup())
197205
logger.info("Initialization completed successfully")

0 commit comments

Comments
 (0)