JuliaCall icon indicating copy to clipboard operation
JuliaCall copied to clipboard

Question: Stop Julia session

Open instantkaffee opened this issue 5 years ago • 5 comments

No issue, just a simple question, maybe an idea for package extension:

Does it make sense to implement a function which terminates a Julia session? Are the ways to do this already ?

Thx

instantkaffee avatar Mar 01 '20 08:03 instantkaffee

Currently there seems to be no way to stop a julia session. Are there any specific use case for this? Thx for the feedback!

Non-Contradiction avatar Mar 01 '20 17:03 Non-Contradiction

This would be useful for my applications that start Julia processes that can run for days at a time. It would be nice to have a way to kill the process without having to close R.

jjlynch2 avatar Mar 11 '20 18:03 jjlynch2

Currently there seems to be no way to stop a julia session. Are there any specific use case for this? Thx for the feedback!

My usecase: I am iterating over many cycles via purrr everytime starting a new Julia instance. I fear this is not memory efficient.

instantkaffee avatar Oct 14 '20 07:10 instantkaffee

@instantkaffee Unless you are starting a new R instance, otherwise JuliaCall will (nearly) always use the existing Julia instance instead of starting a new one.

Non-Contradiction avatar Oct 14 '20 15:10 Non-Contradiction

@jjlynch2 There is still no general solution to stop Julia process in JuliaCall. One idea is to insert R callbacks into the julia function or statement you are executing. For example,

library(JuliaCall)
julia_setup()

jlongcalc <- julia_eval('longcalc() = begin i=0; while(true) i = i+1; RCall.rcall(:print, i); end; i; end;')

In the example, jlongcalc is a Julia function that executes forever by using while(true). However, in the function, an R callback is inserted RCall.rcall(:print, i);. So when the Julia code executes the R callback part, it will give the control back to R, and you can stop it just like stopping any R code. For example, in RStudio, if you jlongcalc(), and click the stop button, then the execution of the function jlongcalc() will be stopped just like any R code. PS: A similar idea is also used in C/RCpp when you have long calculations: if you want the C/Cpp code to respond to R stopping signal, then you need to insert some R callbacks into the C/RCpp code.

One disadvantage for this method is that it is very hard to become a general solution. If JuliaCall automatically inserts R callbacks into users' Julia code, it will make the users' Julia code running slower than it should be.

Non-Contradiction avatar Oct 14 '20 16:10 Non-Contradiction