@@ -146,7 +146,7 @@ as_BatchtoolsFuture <- function(future,
146146 future <- structure(future , class = c(" BatchtoolsFuture" , class(future )))
147147
148148 # # Register finalizer?
149- if (finalize ) future <- add_finalizer(future )
149+ if (finalize ) future <- add_finalizer(future , debug = debug )
150150
151151 future
152152}
@@ -213,6 +213,12 @@ loggedOutput <- function(...) UseMethod("loggedOutput")
213213# ' @export loggedOutput
214214# ' @importFrom batchtools getStatus
215215status.BatchtoolsFuture <- function (future , ... ) {
216+ debug <- getOption(" future.debug" , FALSE )
217+ if (debug ) {
218+ mdebug(" status() for " , class(future )[1 ], " ..." )
219+ on.exit(mdebug(" status() for " , class(future )[1 ], " ... done" ), add = TRUE )
220+ }
221+
216222 # # WORKAROUND: Avoid warnings on partially matched arguments
217223 get_status <- function (... ) {
218224 # # Temporarily disable batchtools output?
@@ -249,6 +255,8 @@ status.BatchtoolsFuture <- function(future, ...) {
249255 if (result_has_errors(result )) status <- unique(c(" error" , status ))
250256 }
251257
258+ if (debug ) mdebug(" - status: " , paste(sQuote(status ), collapse = " , " ))
259+
252260 status
253261}
254262
@@ -735,12 +743,23 @@ delete.BatchtoolsFuture <- function(future,
735743
736744add_finalizer <- function (... ) UseMethod(" add_finalizer" )
737745
738- add_finalizer.BatchtoolsFuture <- function (future , ... ) {
746+ add_finalizer.BatchtoolsFuture <- function (future , debug = FALSE , ... ) {
739747 # # Register finalizer (will clean up registries etc.)
740748
749+ if (debug ) {
750+ mdebug(" add_finalizer() for " , sQuote(class(future )[1 ]), " ..." )
751+ on.exit(mdebug(" add_finalizer() for " , sQuote(class(future )[1 ]), " ... done" ), add = TRUE )
752+ }
753+
741754 reg.finalizer(future , f = function (gcenv ) {
755+ if (debug ) {
756+ 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 )
759+ }
742760 if (inherits(future , " BatchtoolsFuture" ) &&
743761 " future.batchtools" %in% loadedNamespaces()) {
762+ if (debug ) mdebug(" - attempting to delete future" )
744763 try({
745764 delete(future , onRunning = " skip" , onMissing = " ignore" ,
746765 onFailure = " warning" )
0 commit comments