I didn't even know it was possible to fork processes like that. After playing around for a bit, I found the sendChildStdin
function, which you should check out. It is at least one way to signal the child processes. Here is an example:
f<- function () {
message<-scan(n = 1, quiet = TRUE, what='character')
return(message)
}
p <- mcparallel(f())
a <- 1
# The message shouldn't contain spaces and should end with a newline.
parallel:::sendChildStdin(p, "created\n")
mccollect(p)[[1]]
[1] "created"
Don't get me wrong; R is probably not the language you want if you are going to get into the stuff heavily, but it might work for light applications.
I had tested the code before in RStudio, and although it appeared to work, it was failing in a way that was indistinguishable from success. Anyway, it essentially doesn't wait for the scan
process. For example, this should never complete, but it does (in RStudio only)
f<- function () {
message<-scan(n = 1, quiet = TRUE, what='character')
return(message)
}
p <- mcparallel(f())
# parallel:::sendChildStdin(p, "created\n")
mccollect(p)[[1]]
# character(0)
a
in main process.