Repository navigation
Conversation
…early (#29) Closes #29 by narrowing it: its first bullet, a second close() waiting for the interpreter to be closed, is not fixed, but documented instead. As decided, the design of #32 stays: close() returns without waiting whenever something runs on the Python thread, which includes the closing itself, as closing the interpreter runs Python code (__del__) which can wait for a close() on another thread. So only the first close() can wait, and a later one returns at once, also while the interpreter is still being closed. The KDoc of close() and the README say so. Fixed, from the abandoned branch issue-29-close-lifecycle: - a call whose caller is interrupted while waiting for its turn is cancelled with future.cancel(false), and does not run, unless the Python thread has already started it; - close() and the calls restore the interrupt flag when they throw an InterruptedException, as Java code cannot catch it undeclared; - the interpreter reference is released also when closing it fails. Documented with regression tests, already the behavior of main: a failure of closing the interpreter is thrown by the close() waiting for it, and not again by a later close(), so that use or try-with-resources around an explicit close() reports it once; a close() reached from __del__ during closing, directly or from another thread, does not deadlock. Python.withInterpreterFactory is a new internal test seam, to make closing the interpreter fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FJmHQ3jHRbVdpwUiNUkApG
) Polish after the review of the fix of #29: - an InterruptedException thrown by a call or close() no longer sets the interrupt flag again, as it made the next blocking operation of the caller, e.g. the close() of use { }, fail at once; the public functions which can throw it declare it with @throws, so that Java callers can catch it; - the README tells that an interrupted close() throws at once, while the interpreter is still closed later, in the background; - the comment on releasing the interpreter in finally says it is defensive only; - the default interpreter factory is a default parameter value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FJmHQ3jHRbVdpwUiNUkApG
…#69) When the waiting close() was interrupted, or returned at once with a call running, a failure of closing the interpreter stayed in a future nobody read. It is now logged as a WARNING of the System.Logger of Python, exactly once, by whichever side comes second: the closing task, or the close() giving up on it. A close() waiting for it still throws it, and nothing is logged then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FJmHQ3jHRbVdpwUiNUkApG
#69) The logging of a failure of closing the interpreter cannot throw anymore, so the closing task still rethrows the failure, and an interrupted close() still throws its InterruptedException. The logger is created only when needed, the closing state is a sealed type, and a failure thrown by close() is no longer kept. The log capture of the tests filters by the expected failure, and does not pass the records on to the console. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FJmHQ3jHRbVdpwUiNUkApG
#71, which this branch was stacked on, was squash-merged into main as f7b4a2e. Main holds the same content as #71's branch, so the conflicts (README.md, Python.kt, PythonCloseTest.kt) take this branch's side, leaving only the changes of #86 on top of main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FJmHQ3jHRbVdpwUiNUkApG
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.
Fixes #69
Stacked on #71 (fix of #29) — merge #71 into
mainfirst (bottom-up, see CLAUDE.md); GitHub retargets this PR when the base branch is deleted.A failure of closing the interpreter is no longer lost when no
close()waits for it — the waitingclose()was interrupted, orclose()returned at once because a call was running: it is logged once, as aWARNINGof theSystem.Loggercom.xemantic.kotlin.script.python.Python(no new dependency).close()that stops waiting race on one state (ClosingState:Abandoned/Failed); whichever comes second logs, so the failure is reported exactly once — thrown by the waitingclose(), or logged.close()calls return at once, theclose()waiting for the closing throws its failure,use/ try-with-resources unchanged.InterruptedException), and the logger is created lazily.Review
1 round — no blocking findings (exactly-once and the contract traced through every path). Polish applied:
runCatchingaround logging, lazy logger, typed state, test log capture filtered by exception instance and without parent handlers, KDoc order.🤖 Generated with Claude Code
https://claude.ai/code/session_01FJmHQ3jHRbVdpwUiNUkApG