Skip to content

Commit 0687c40

Browse files
authored
warnings ignored in frollapply (#7287)
1 parent 4f6a365 commit 0687c40

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

R/frollapply.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ frollapply = function(X, N, FUN, ..., by.column=TRUE, fill=NA, align=c("right","
260260
}
261261
## prepare templates for errors and warnings
262262
err.collect = gettext("frollapply calling parallel::mccollect to collect results from forked processes raised an error.\n%s")
263-
warn.collect = gettext("frollapply calling parallel::mccollect to collect results from forked processes raised a warning.\n%s")
263+
warn.collect = gettext("frollapply internal call to parallel::mccollect raised a warning, FUN warnings should have been suppressed by parallel.\n%s")
264264
if (is.function(simplify)) {
265265
err.simplify = gettext("frollapply completed successfully but raised an error when attempting to simplify results using user specified function in 'simplify' argument. Be sure to provide 'fill' argument matching the type and shape of results returned by the your function. Use simplify=FALSE to obtain a list instead.\n%s")
266266
warn.simplify = gettext("frollapply completed successfully but raised a warning when attempting to simplify results using user specified function in 'simplify' argument. Be sure to provide 'fill' argument matching the type and shape of results returned by the your function. Use simplify=FALSE to obtain a list instead.\n%s")
@@ -310,7 +310,9 @@ frollapply = function(X, N, FUN, ..., by.column=TRUE, fill=NA, align=c("right","
310310
tryCatch(
311311
parallel::mccollect(jobs),
312312
error = function(e) stopf(err.collect, e[["message"]]),
313-
warning = function(w) warningf(warn.collect, w[["message"]])
313+
warning = function(w) {
314+
warningf(warn.collect, w[["message"]]) # nocov
315+
}
314316
),
315317
interrupt = function(e) {
316318
# nocov start
@@ -341,11 +343,14 @@ frollapply = function(X, N, FUN, ..., by.column=TRUE, fill=NA, align=c("right","
341343
tryCatch(
342344
thisans <- lapply(ansi, FUN = tight, dest = cpy(w), src = thisx, n = thisn),
343345
error = function(e) h$err = conditionMessage(e)
344-
), warning = function(w) {h$warn = c(h$warn, conditionMessage(w)); invokeRestart("muffleWarning")}
346+
), warning = function(w) {
347+
#h$warn = c(h$warn, conditionMessage(w)) ## warnings are suppressed for consistency to parallel processing code
348+
invokeRestart("muffleWarning")
349+
}
345350
)
346351
setDTthreads(oldDTthreads)
347-
if (!is.null(h$warn))
348-
warningf("frollapply received a warning(s) when evaluating FUN:\n%s", paste(unique(h$warn), collapse="\n"))
352+
#if (!is.null(h$warn)) ## warnings are suppressed for consistency to parallel processing code
353+
# warningf("frollapply received a warning(s) when evaluating FUN:\n%s", paste(unique(h$warn), collapse="\n"))
349354
if (!is.null(h$err))
350355
stopf("frollapply received an error(s) when evaluating FUN:\n%s", h$err)
351356
}

inst/tests/froll.Rraw

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,12 +1165,17 @@ if (use.fork) {
11651165
}
11661166
old = setDTthreads(1L)
11671167
options(datatable.verbose=TRUE)
1168-
test(6010.025, frollapply(1:2, 1, identity), c(2L,2L), output="running on single CPU thread")
1168+
test(6010.025, frollapply(1:2, 1, copy), c(1L,2L), output="running on single CPU thread")
11691169
options(datatable.verbose=FALSE)
1170-
test(6010.026, frollapply(1:2, 1, function(x) {warning("warn"); x}), c(2L,2L), warning="warn")
1171-
test(6010.027, frollapply(1:2, 1, function(x) {warning("warn:", tail(x,1)); x}), c(2L,2L), warning="warn:1\nwarn:2")
1172-
test(6010.028, frollapply(1:2, 1, function(x) {stop("err:", tail(x,1)); x}), error="err:1") ## only first
1170+
test(6010.026, frollapply(1:2, 1, function(x) {warning("warn"); copy(x)}), c(1L,2L))
1171+
test(6010.027, frollapply(1:2, 1, function(x) {warning("warn:", tail(x,1)); copy(x)}), c(1L,2L))
1172+
test(6010.028, frollapply(1:2, 1, function(x) {stop("err:", tail(x,1)); copy(x)}), error="err:1") ## only first
11731173
setDTthreads(old)
1174+
if (getDTthreads()>1L) { ## check for consistency
1175+
test(6010.036, frollapply(1:2, 1, function(x) {warning("warn"); copy(x)}), c(1L,2L))
1176+
test(6010.037, frollapply(1:2, 1, function(x) {warning("warn:", tail(x,1)); copy(x)}), c(1L,2L))
1177+
test(6010.038, frollapply(1:2, 1, function(x) {stop("err:", tail(x,1)); copy(x)}), error="err:1") ## only first
1178+
}
11741179

11751180
#### corner cases from examples - handled properly after frollapply rewrite to R
11761181
test(6010.101, frollapply(1:5, 3, function(x) head(x, 2)), list(NA, NA, 1:2, 2:3, 3:4))

man/frollapply.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ frollapply(c(1, 9), N=1L, FUN=function(x) copy(list(x)))
7474
}
7575
\item \code{FUN} calls are internally passed to \code{parallel::mcparallel} to evaluate them in parallel. We inherit few limitations from \code{parallel} package explained below. This optimization can be disabled completely by calling \code{setDTthreads(1)}, then limitations listed below do not apply because all iterations of \code{FUN} evaluation will be made sequentially without use of \code{parallel} package. Note that on Windows platform this optimization is always disabled due to lack of \emph{fork} used by \code{parallel} package. One can use \code{options(datatable.verbose=TRUE)} to get extra information if \code{frollapply} is running multithreaded or not.
7676
\itemize{
77-
\item Warnings produced inside the function are silently ignored.
77+
\item Warnings produced inside the function are silently ignored; for consistency we ignore warnings also when running single threaded path.
7878
\item \code{FUN} should not use any on-screen devices, GUI elements, tcltk, multithreaded libraries. Note that \code{setDTthreads(1L)} is passed to forked processes, therefore any data.table code inside \code{FUN} will be forced to be single threaded. It is advised to not call \code{setDTthreads} inside \code{FUN}. \code{frollapply} is already parallelized and nested parallelism is rarely a good idea.
7979
\item Any operation that could misbehave when run in parallel has to be handled. For example writing to the same file from multiple CPU threads.
8080
\preformatted{

0 commit comments

Comments
 (0)