Skip to content

fix(ci): resolve pytest hang after tests pass (loguru __del__ deadlock)#1

Merged
incrementaliser merged 1 commit into
mainfrom
cursor/fix-ci-hang-loguru-del-0953
May 18, 2026
Merged

fix(ci): resolve pytest hang after tests pass (loguru __del__ deadlock)#1
incrementaliser merged 1 commit into
mainfrom
cursor/fix-ci-hang-loguru-del-0953

Conversation

@incrementaliser
Copy link
Copy Markdown
Owner

Problem

CI reported success (191 passed, 2 skipped in ~4.5s) then stalled until the job timeout (~45 minutes). The hang occurs after pytest finishes, during interpreter shutdown.

Root cause

InteractiveContextParser.__del__ called loguru.remove() for each parser's sinks. When several parsers with active logging are garbage-collected together (common after the loguru integration and increased parser usage from parallel language-derivation tests), loguru's internal lock is re-entered from nested __del__ calls and the main thread deadlocks.

This reproduces locally with:

uv run pytest tests/test_icp_logging.py::test_log_level_error_captures_unknown_word \
  tests/test_icp_logging.py::test_log_level_warning_suppresses_info

Parallelisation/Rich/ProcessPoolExecutor mitigations on main were reasonable hardening but did not fix this primary failure mode.

Fix

  • Remove __del__ sink cleanup; add explicit close() / _remove_icp_log_sinks().
  • Restore spawn multiprocessing context for ProcessPoolExecutor in language derivation (safe for real parallel runs outside pytest).
  • Add a small regression test for the two-parser terminal-log scenario.

Verification

  • Full suite: uv run pytest -q191 passed, 2 skipped and exit code 0 (previously hung with exit 124 under timeout).
Open in Web Open in Cursor 

… exit

InteractiveContextParser.__del__ called loguru.remove() during GC of
multiple parsers, re-entering loguru's handler lock and hanging after all
tests passed. Replace with an explicit close() and restore spawn for
ProcessPoolExecutor in language derivation.

Co-authored-by: Arash Ashrafzadeh <arashmath16@gmail.com>
@incrementaliser incrementaliser marked this pull request as ready for review May 18, 2026 22:46
@incrementaliser incrementaliser merged commit 9b39a5d into main May 18, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants