Repository navigation
Description
I've implemented support for registering a global condition handler (requires R >= 4.0.0) that will listen to progress updates (formally 'progression' conditions) and render them. When used, there is no need for with_progress(). As the below example illustrates, it buffers and flushes standard output and messages (and warnings). Just like before, it also works when parallelizing using the future framework.
Here's an example:
library(progressr)
slow_fcn <- function(xs) {
p <- progressor(along = xs)
p(sprintf("Starting", amount = 0))
y <- lapply(xs, function(x) {
cat(sprintf("[stdout]: x = %g\n", x))
Sys.sleep(0.5)
z <- sqrt(x)
message(sprintf("[message]: z = %g", z))
p(sprintf("Processed x = %g", x))
z
})
sum(unlist(y))
}handlers(global = TRUE)
y <- slow_fcn(1:3)
# [stdout]: x = 1
# [message]: z = 1
# [stdout]: x = 2
|========== | 33%To disable the global handlers, use:
handlers(global = FALSE)Please give it a spin by installing the develop branch;
remotes::install_github("HenrikBengtsson/progressr", ref = "develop")Tasks
-
Test it in real-world scenarios:
- Bugs identified and fixed this far: BETA: Global progress handler #95 (comment)
-
The name
register_global_progression_handler()is a bit much and should be renamed to something shorter. If someone got a better name, please let me know. UPDATE 2020-12-04: We're now usinghandlers(global = TRUE)andhandlers(global = FALSE)for this.
An alternative is to make handlers("void") the default, which will also unregister any global progression handler. When setting any other progression handler(s), say handlers("progress"), then the global progression handler will be automatically registered as well. This way the end-user interface will be to use handlers().
Activity
Bisaloo commentedon Nov 18, 2020
I tried to follow your instructions but I get
which was not the case before. Any idea what went wrong and how to fix it?
HenrikBengtsson commentedon Nov 18, 2020
@Bisaloo, thanks for the feedback. That error message comes from an internal sanity check. I'd like to be able to reproduce this. Can you give me a bit more details, e.g.
Do you get any output at all?
After you get that error message, what does
traceback()give?What's your
sessionInfo()after you get the error?Are you running R in the terminal, in RStudio, or elsewhere?
Bisaloo commentedon Nov 18, 2020
No, I get
NULL. There is a small chance thisNULLactually comes from my own code after encountering the error though.traceback
sessionInfo
RStudio
You can probably reproduce this issue with:
HenrikBengtsson commentedon Nov 18, 2020
Thanks, I misunderstood your initial "I tried to follow your instructions" to mean that the example in #95 (comment) failed. Do you mind confirming that at least that one works for you?
Bisaloo commentedon Nov 18, 2020
Ah yes, this was confusing indeed. I confirm the example in the OP works perfectly for me.
HenrikBengtsson commentedon Nov 18, 2020
Thxs. I can reproduce the error with your package example.
HenrikBengtsson commentedon Nov 18, 2020
I can reproduce the problem with:
with the end of the traceback being:
The problem goes away if I allow for one more progressor step, e.g.
p <- progressor(steps + 1L). It also goes away if I drop thep(). Also, replacingfuture.apply::future_lapply()with a planlapply()works.This means I've got something to work with to fix this.
BUG FIX: When closing the progressor, it might not be possible to clo…
HenrikBengtsson commentedon Nov 18, 2020
I think I fixed it. @Bisaloo, please re-install the develop version and retry.
Details: The problem was that the internal sanity check assumed that the sink+connection used to buffer stdout could be closed at any time, e.g. when the progressor reaches 100%. This was not possible when it reached 100% inside a future because the future had another sink active blocking the progressors sink from being close. Here's a simpler reproducible example of this problem without futures;
Bisaloo commentedon Nov 19, 2020
Yes, I can confirm it is fixed for me. Thank you very much for the quick fix!
HenrikBengtsson commentedon Dec 2, 2020
Instead of the end-user having to call:
I'm thinking of providing
Adding handlers(globals = TRUE) for the global progression handler [#95]
HenrikBengtsson commentedon Dec 4, 2020
I've pushed support for:
Next, I'll remove
register_global_progression_handler()from the public API.No longer need to export register_global_progression_handler(); use h…
HenrikBengtsson commentedon Dec 6, 2020
I've updated the README and the vignette (they're the same) to mainly use global progress handling in all of the examples.
REVDEP: 22 packages with global handler enabled [#95] [ci skip]
HenrikBengtsson commentedon Dec 11, 2020
Finally managed to run revdep checks where all package tests are run with `progressr::handlers(global = TRUE) - took some hacking. The good news is that is no negative impact to enable the global progression handler.