Skip to content

Implement user interrupt from R#276

Open
vandenman wants to merge 3 commits intoJuliaInterop:masterfrom
vandenman:interrupt
Open

Implement user interrupt from R#276
vandenman wants to merge 3 commits intoJuliaInterop:masterfrom
vandenman:interrupt

Conversation

@vandenman
Copy link
Copy Markdown

Description

Before evaluating the Julia code, we start a Timer that listens to :R_interrupts_pending. This idea is copied from RCall, see here, and also mentioned in a comment. When R_interrupts_pending is set, we throw an InterruptException() which is then caught and we exit Julia gracefully to return control to R.

Related Issue

This is related to #126, but this does not close/ restart the Julia session. It only interrupts it.

Example

Interactively, you can do the following on master:

julia_setup()
julia_install_package_if_needed("ProgressMeter")
julia_command("using ProgressMeter")

julia_command('@showprogress "Working..." for i in 1:100
    sleep(0.5)
end')

There is no way to interrupt this. It will run until it's done, or you force quit R/ RStudio. In contrast, on this PR, you can interrupt R (e.g., press the red stop button in RStudio) and then the loop will stop.

More realistic scenarios are situations where someone accidentally runs an analysis for way more iterations than intended, and then has to choose between waiting a long time or restarting the session and loosing the interim progress.

Questions

  • It's unlikely but possible that the Julia code itself throws a InterruptException. We could make a custom exception, InterruptedFromRException and throw that instead?

I added the renv stuff to .Rbuildignore since this is what renv does by default. If this is a problem I'd of course be happy to revert that.

Developed with Claude 🤖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant