Skip to content

Commit fe22578

Browse files
CLEANUP: Import private functions from 'future', e.g. sQuoteLabel()
1 parent 84b90ef commit fe22578

File tree

5 files changed

+35
-23
lines changed

5 files changed

+35
-23
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future.batchtools
2-
Version: 0.12.1-9007
2+
Version: 0.12.1-9008
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

NEWS.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# Version (development version)
22

3-
* ...
4-
3+
## Bug Fixes
4+
5+
* Attempts to cancel batchtools futures via `cancel()` would result in
6+
"Interruption of futures require a backend implementing the
7+
FutureBackend API". Until this package implements the new
8+
FutureBackend API of future (>= 1.40.0), any calls to `cancel()`
9+
will be silently ignored.
10+
511

612
# Version 0.12.1 [2023-12-19]
713

R/001.import_future_functions.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## To be imported from 'future', if available
2+
readImmediateConditions <- NULL
3+
signalEarly <- NULL
4+
FutureRegistry <- NULL
5+
sQuoteLabel <- NULL
6+
.debug <- NULL
7+
8+
## Import private functions from 'future'
9+
import_future_functions <- function() {
10+
readImmediateConditions <<- import_future("readImmediateConditions")
11+
signalEarly <<- import_future("signalEarly")
12+
FutureRegistry <<- import_future("FutureRegistry")
13+
14+
## future (>= 1.49.0)
15+
sQuoteLabel <<- import_future("sQuoteLabel")
16+
17+
.debug <<- import_future(".debug", mode = "environment", default = new.env(parent = emptyenv()))
18+
}

R/BatchtoolsFuture-class.R

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ loggedError.BatchtoolsFuture <- function(future, ...) {
309309
if (is_na(stat)) return(NULL)
310310

311311
if (!finished(future)) {
312-
label <- future$label
313-
if (is.null(label)) label <- "<none>"
312+
label <- sQuoteLabel(future)
314313
msg <- sprintf("%s ('%s') has not finished yet", class(future)[1L], label)
315314
stop(BatchtoolsFutureError(msg, future = future))
316315
}
@@ -335,8 +334,7 @@ loggedOutput.BatchtoolsFuture <- function(future, ...) {
335334
if (is_na(stat)) return(NULL)
336335

337336
if (!finished(future)) {
338-
label <- future$label
339-
if (is.null(label)) label <- "<none>"
337+
label <- sQuoteLabel(future)
340338
msg <- sprintf("%s ('%s') has not finished yet", class(future)[1L], label)
341339
stop(BatchtoolsFutureError(msg, future = future))
342340
}
@@ -356,8 +354,6 @@ loggedOutput.BatchtoolsFuture <- function(future, ...) {
356354
#' @export
357355
#' @keywords internal
358356
resolved.BatchtoolsFuture <- function(x, ...) {
359-
signalEarly <- import_future("signalEarly")
360-
361357
## Is value already collected?
362358
if (!is.null(x$result)) {
363359
## Signal conditions early?
@@ -413,8 +409,7 @@ result.BatchtoolsFuture <- function(future, cleanup = TRUE, ...) {
413409
if (debug) mdebug("- getting batchtools status")
414410
stat <- status(future)
415411
if (is_na(stat)) {
416-
label <- future$label
417-
if (is.null(label)) label <- "<none>"
412+
label <- sQuoteLabel(future)
418413
stopf("The result no longer exists (or never existed) for Future ('%s') of class %s", label, paste(sQuote(class(future)), collapse = ", ")) #nolint
419414
}
420415

@@ -442,8 +437,7 @@ result.BatchtoolsFuture <- function(future, cleanup = TRUE, ...) {
442437
#' @export
443438
run.BatchtoolsFuture <- function(future, ...) {
444439
if (future$state != "created") {
445-
label <- future$label
446-
if (is.null(label)) label <- "<none>"
440+
label <- sQuoteLabel(future)
447441
msg <- sprintf("A future ('%s') can only be launched once.", label)
448442
stop(FutureError(msg, future = future))
449443
}
@@ -581,8 +575,7 @@ run.BatchtoolsFuture <- function(future, ...) {
581575
})
582576
}, error = function(ex) {
583577
msg <- conditionMessage(ex)
584-
label <- future$label
585-
if (is.null(label)) label <- "<none>"
578+
label <- sQuoteLabel(future)
586579
msg <- sprintf("Failed to submit %s (%s). The reason was: %s", class(future)[1], label, msg)
587580
info <- capture.output(str(resources))
588581
info <- paste(info, collapse = "\n")
@@ -649,8 +642,7 @@ await <- function(future, cleanup = TRUE,
649642
result <- NULL
650643
if (finished) {
651644
mdebug("Results:")
652-
label <- future$label
653-
if (is.null(label)) label <- "<none>"
645+
label <- sQuoteLabel(future)
654646
if ("finished" %in% stat) {
655647
if (debug) mdebug("- batchtools::loadResult() ...")
656648
result <- loadResult(reg = reg, id = jobid)
@@ -780,8 +772,7 @@ delete.BatchtoolsFuture <- function(future,
780772
if (!resolved(future)) {
781773
if (onRunning == "skip") return(invisible(TRUE))
782774
status <- status(future)
783-
label <- future$label
784-
if (is.null(label)) label <- "<none>"
775+
label <- sQuoteLabel(future)
785776
msg <- sprintf("Will not remove batchtools registry, because is appears to hold a non-resolved future (%s; state = %s; batchtools status = %s): %s", sQuote(label), sQuote(future$state), paste(sQuote(status), collapse = ", "), sQuote(path)) #nolint
786777
mdebugf("delete(): %s", msg)
787778
if (onRunning == "warning") {

R/zzz.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
## To be cached by .onLoad()
2-
FutureRegistry <- NULL
3-
42
.onLoad <- function(libname, pkgname) {
5-
## Import private functions from 'future'
6-
FutureRegistry <<- import_future("FutureRegistry")
3+
import_future_functions()
74

85
debug <- getOption("future.debug", FALSE)
96

0 commit comments

Comments
 (0)