5

Problem Version 1, Can we make pr_fun process it's retun without waiting for ch_fun() to finish

ch_fun <- function() {Sys.sleep(10)}
pr_fun <- function() {ch_fun(); return("Done")}
pr_fun()

Proble Actual Version

R session 1 as svSocket Server

library(svSocket)
startSocketServer(port = 9875,local=FALSE)

R session 2 as svSocket client

con <- socketConnection(port = 9875,host="127.0.0.1")
evalServer(con,"Sys.sleep(20)")

R session 3 as svSocket client

con <- socketConnection(port = 9875,host="127.0.0.1")
evalServer(con,"a=10")

If we run the code lines for session 2 and while server is processing Sys.sleep call we quickly put the code lines for session 3 in session 3 and abort the call it still gets processed. We can check that on server side by checking if object "a" was created.

My point is we didn't have to wait for job to finish in session 3 still it was processed so somehow jobs were piled up on session side and we don't have to wait for jobs to finish just send them to server and abort the waiting process and move ahead. We can manually abort using Ctrl+C or Esc but how can I do that in a function. I want pr_fun to call ch_fun in server session and proceed to its return immediately.

anonR
  • 849
  • 7
  • 26
  • Is "problem 1" essentially "make `pr_fun` multi-threaded"? – r2evans Feb 22 '17 at 16:49
  • Don't know technically, But I want the pr_fun to process it's return while earlier command is getting processed. I know it doesn't seem possible in problem1 but I really think it should be doable in Problem Actual version using svSocket – anonR Feb 22 '17 at 16:52
  • If I understand Rserve, you are connecting with 3 distinct clients to a single R process. This single R process handles its requests consecutively, meaning your client 3 above has to wait in line while client 2 sleeps. I cannot find a function in `RSclient` that "dequeues" an expression already submitted, and though I don't know `svSocket`, it seems like the underlying `Rserve` does not have that functionality. Perhaps you should [contact the author](http://simon.urbanek.info/) directly, as I fear what you are suggesting is not trivial. – r2evans Feb 22 '17 at 17:10

0 Answers0