Print messages to console as soon as they are generated #572
Replies: 2 comments
-
Hi. Let me start by explaining the current behavior. I'll end with a solution.
This is by design. The future.apply package replicates the behavior of the corresponding apply functions in base R. This way the threshold from going, say,
I want to say a few things here, and you might know this already, but I wanna make it clear for everyone else who reads this. There are two kinds of output in R: (i) directly to the standard output (stdout) and (ii) via R's condition system. stdout: The traditional Now, depending on your operating system, your R environment (e.g. conditions: In constrast to above stdout functions, functions like In your example code, you are using
Looking at your example, it looks like you want to output messages that convey progress. If so, I highly recommend that you use the progressr package. It signals and relays progress information as soon as possible, independently of the order futures are finished. It supports parallel processing and there are examples how to use it with futures, e.g. https://progressr.futureverse.org/#parallel-processing-and-progress-updates. library(future.apply)
plan(multisession)
library(progressr)
handlers(global = TRUE)
handlers("progress")
y <- local({
p <- progressor(2)
future_apply(array(1:2), 1, function(i) {
Sys.sleep(abs(i-2)*20)
p(paste("Process",i,"completed !"))
})
}) will output
If you want to "output" progress messages that remain afterward, see https://progressr.futureverse.org/#sticky-messages. See https://progressr.futureverse.org/#known-issues for the reason why we need to use Hope this helps |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for your very comprehensive reply. Thanks, and happy new year ! |
Beta Was this translation helpful? Give feedback.
-
Hello,
I've been trying to print message to console as soon as they are generated.
I know this question has already been addressed (e.g. here), but I did not find a satisfactory answer.
I'm using future to run different parallel processes, and I would like to print a message to the console as soon as one of this process is finished.
Using
future.conditions = "message", future.stdout = NA
options, I was able to print some messages before the global process is over, but not as soon as the messages are generated.For example, say I would like to print each process id when it is completed with something like:
Even if the process n°2 is completed before process n°1, the console do not print "Process 2 completed !" first.
Thank you for your help !
Beta Was this translation helpful? Give feedback.
All reactions