Code Monkey home page Code Monkey logo

Comments (9)

randy3k avatar randy3k commented on August 18, 2024

Eventloop was implemented in RCalling.jl and Rif.jl. See for example this link. The code was written in C, however, it should be easy to port it to Julia. I can submit a PR this afternoon.

from rcall.jl.

randy3k avatar randy3k commented on August 18, 2024

Please checkout the current master branch for the eventloop. Basically, there are two functions: RCall.rgui_start() and RCall.rgui_stop().

from rcall.jl.

simonbyrne avatar simonbyrne commented on August 18, 2024

Once we have callbacks sorted out, we could automate this using setHook.

from rcall.jl.

randy3k avatar randy3k commented on August 18, 2024

In the eventloop, there was a dirty fix related to sigint. The problem was when a sigint is signaled from Julia (pressing Control - C), the R_interrupts_pending is set to state 1. Without a proper R eventloop, R_interrupts_pending remains state 1. And it causes segfault when evaluating R_ProcessEvents. So R_interrupts_pending was forced to be 0 in there.

For a while, I only think that it is needed for R_ProcessEvents. Until just now, I discovered this

julia> using RCall

julia> reval("gc()")
RCall.RObject{RCall.RealSxp}
         used (Mb) gc trigger (Mb) max used (Mb)
Ncells 219236 11.8     460000 24.6   350000 18.7
Vcells 322397  2.5     786432  6.0   786432  6.0


julia> unsafe_load(cglobal((:R_interrupts_pending,RCall.libR),Cint))
0

julia> ^C

julia> unsafe_load(cglobal((:R_interrupts_pending,RCall.libR),Cint))
1

julia> reval("gc()")
ERROR: RCall.jl 

 in error at error.jl:22
 in reval_p at /Users/Randy/.julia/v0.4/RCall/src/iface.jl:11
 in reval_p at /Users/Randy/.julia/v0.4/RCall/src/iface.jl:19
 in reval at /Users/Randy/.julia/v0.4/RCall/src/iface.jl:29
 in reval at /Users/Randy/.julia/v0.4/RCall/src/iface.jl:31

julia> unsafe_load(cglobal((:R_interrupts_pending,RCall.libR),Cint))
0

julia> reval("gc()")

signal (11): Segmentation fault: 11
sexp at /Users/Randy/.julia/v0.4/RCall/src/types.jl:332
jlcall_sexp_21406 at  (unknown line)
reval_p at /Users/Randy/.julia/v0.4/RCall/src/iface.jl:18
reval at /Users/Randy/.julia/v0.4/RCall/src/iface.jl:29
jlcall_reval_21501 at  (unknown line)
reval at /Users/Randy/.julia/v0.4/RCall/src/iface.jl:31
jl_apply at /opt/local/julia/src/interpreter.c:55
eval at /opt/local/julia/src/interpreter.c:213
jl_toplevel_eval_flex at /opt/local/julia/src/toplevel.c:527
jl_toplevel_eval_in at /opt/local/julia/src/builtins.c:579
eval_user_input at REPL.jl:62
jlcall_eval_user_input_21271 at  (unknown line)
anonymous at REPL.jl:92
jl_apply at /opt/local/julia/src/task.c:241
Selection: 

But interestingly, if reval("gc()") is replaced by rcall(:gc), it causes no issues.

It means that we might need to check the value of R_interrupts_pending constantly.

from rcall.jl.

randy3k avatar randy3k commented on August 18, 2024

One possible solution is to disable signal handling

    if !Rinited
        unsafe_store!(cglobal((:R_SignalHandlers,libR),Cint),0)
        argv = ["REmbeddedJulia","--silent","--no-save"]
        i = ccall((:Rf_initEmbeddedR,libR),Cint,(Cint,Ptr{Ptr{UInt8}}),length(argv),argv)
        i > 0 || error("initEmbeddedR failed. Try restarting and running Pkg.build(\"RCall\").")
        global const Rproc = Rinstance(i)
    end

from rcall.jl.

randy3k avatar randy3k commented on August 18, 2024

Though the eventloop implementation is still primitive, I believe this thread could be closed (at least for now).

from rcall.jl.

simonbyrne avatar simonbyrne commented on August 18, 2024

One thought: in the timer loop we could check if there are any open graphics devices, and if not, close the timer?

from rcall.jl.

randy3k avatar randy3k commented on August 18, 2024

If I am correct, the timer loop is also needed for some X11 applications and they are not necessary graphics.

from rcall.jl.

simonbyrne avatar simonbyrne commented on August 18, 2024

We could create a graphic-specific one (started by a hook), and a general (manual) one?

from rcall.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.