-
Notifications
You must be signed in to change notification settings - Fork 92
Description
Describe the bug
Similar to futureverse/future.mirai#17, I'm adapting immediateMessage as mentioned in futureverse/progressr#176 for multisession.
It seems to work for the initial tasks, but others require an attempt to realize the value before it is printed.
Reproduce example
I'll source all of this code first. Since I'm starting two workers, the x and y expressions start immediately, and the third is intended to be queued and will process when the first two clear.
immediateMessage <- function (..., domain = NULL, appendLF = TRUE) {
# prepend the time, perhaps sloppy but good for demonstration
msg <- .makeMessage(c(format(Sys.time()), " ", ...), domain = domain, appendLF = appendLF)
call <- sys.call()
cond <- simpleMessage(msg, call)
class(cond) <- c(class(cond), "immediateCondition")
message(cond)
}
library(future)
plan(multisession, workers=2)
x %<-% { immediateMessage("in x"); Sys.sleep(2); immediateMessage(paste("x ", Sys.getpid())); Sys.sleep(2); 3.14 }
y %<-% { immediateMessage("in y"); Sys.sleep(2); immediateMessage(paste("y ", Sys.getpid())); Sys.sleep(2); 2.71 }
z %<-% { immediateMessage("in z"); Sys.sleep(2); immediateMessage(paste("z ", Sys.getpid())); Sys.sleep(2); 1.62 }
x+yIf I source that block, then I see
library(future)
plan(multisession, workers=2)
x %<-% { immediateMessage("in x"); Sys.sleep(2); immediateMessage(paste("x ", Sys.getpid())); Sys.sleep(2); 3.14 }
y %<-% { immediateMessage("in y"); Sys.sleep(2); immediateMessage(paste("y ", Sys.getpid())); Sys.sleep(2); 2.71 }
z %<-% { immediateMessage("in z"); Sys.sleep(2); immediateMessage(paste("z ", Sys.getpid())); Sys.sleep(2); 1.62 }
# 2025-01-31 11:41:22 in x
# 2025-01-31 11:41:22 in y
# 2025-01-31 11:41:24 x 9219
# 2025-01-31 11:41:24 y 9218
x+y
# [1] 5.85As I said in the other issue, the fact that x+y shows after the messages indicates that some messages are immediate.
Once that's done, I pause for a moment and see that the z messages do not appear. If I then manually type z in the console, I immediately see:
z; Sys.time()
# 2025-01-31 11:41:26 in z
# 2025-01-31 11:41:28 z 9219
# [1] 1.62
# [1] "2025-01-31 11:42:25 EST"It is clear to me that the execution was in fact scheduled immediately after one of x or y completed, but the messages themselves did not appear until I evaluated z (and the 11:42:25 indicates the time between when I pasted here, then typed some comments, and then went back to the console, demonstrating that the z code executed correctly on time).
A reproducible example using R code.
Please format your inline code and code blocks using Markdown (https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax).
Expected behavior
I expect the z messages would appear on the console immediately after one of the x or y tasks is complete.
Session information
sessionInfo()
R version 4.3.3 (2024-02-29) Platform: aarch64-apple-darwin20 (64-bit) Running under: macOS 15.2 Matrix products: default BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0 locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 time zone: America/New_York tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] future.mirai_0.2.2 future_1.34.0 r2_0.12.0 loaded via a namespace (and not attached): [1] mirai_2.0.1 digest_0.6.37 codetools_0.2-20 fastmap_1.2.0 xfun_0.49 nanonext_1.5.0 knitr_1.49 parallel_4.3.3 htmltools_0.5.8.1 [10] rmarkdown_2.29 cli_3.6.3 parallelly_1.40.1 compiler_4.3.3 globals_0.16.3 tools_4.3.3 listenv_0.9.1 clipr_0.8.0 evaluate_1.0.1 [19] rlang_1.1.5