Skip to content

Commit ecfa308

Browse files
More debug output for batchtools finalizers
1 parent 56d8dcd commit ecfa308

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

R/BatchtoolsFuture-class.R

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -751,19 +751,29 @@ add_finalizer.BatchtoolsFuture <- function(future, debug = FALSE, ...) {
751751
on.exit(mdebug("add_finalizer() for ", sQuote(class(future)[1]), " ... done"), add = TRUE)
752752
}
753753

754-
reg.finalizer(future, f = function(gcenv) {
754+
reg.finalizer(future, f = function(f) {
755755
if (debug) {
756756
if (!exists("mdebug", mode = "function")) mdebug <- message
757-
mdebug("Finalize ", sQuote(class(future)[1]), " ...")
758-
on.exit(mdebug("Finalize ", sQuote(class(future)[1]), " ... done"), add = TRUE)
757+
mdebug("Finalize ", sQuote(class(f)[1]), " ...")
758+
on.exit(mdebug("Finalize ", sQuote(class(f)[1]), " ... done"), add = TRUE)
759759
}
760-
if (inherits(future, "BatchtoolsFuture") &&
761-
"future.batchtools" %in% loadedNamespaces()) {
762-
if (debug) mdebug("- attempting to delete future")
763-
try({
764-
delete(future, onRunning = "skip", onMissing = "ignore",
765-
onFailure = "warning")
760+
if (inherits(f, "BatchtoolsFuture") && "future.batchtools" %in% loadedNamespaces()) {
761+
if (debug) {
762+
mdebug("- attempting to delete future")
763+
if (requireNamespace("utils", quietly = TRUE)) {
764+
mdebug(utils::capture.output(utils::str(as.list(f))))
765+
}
766+
}
767+
res <- try({
768+
delete(f, onRunning = "skip", onMissing = "ignore", onFailure = "warning")
766769
})
770+
if (debug) {
771+
if (inherits(res, "try-error")) {
772+
mdebug("- Failed to delete: ", sQuote(res))
773+
} else {
774+
mdebug("- deleted: ", res)
775+
}
776+
}
767777
}
768778
}, onexit = TRUE)
769779

0 commit comments

Comments
 (0)