Skip to content

Commit f2d6921

Browse files
Add support for state 'submitted' as well; this will be useful for HPC schedulers, but also other types of backends with a queue
1 parent 9acaafe commit f2d6921

File tree

7 files changed

+17
-16
lines changed

7 files changed

+17
-16
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future
2-
Version: 1.67.0-9011
2+
Version: 1.67.0-9012
33
Title: Unified Parallel and Distributed Processing in R for Everyone
44
Depends:
55
R (>= 3.2.0)

R/backend_api-Future-class.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ getExpression.Future <- local({
10241024
#' @export
10251025
`$<-.Future` <- function(x, name, value) {
10261026
if (name == "state") {
1027-
if (!is.element(value, c("created", "running", "finished", "failed", "canceled", "interrupted"))) {
1027+
if (!is.element(value, c("created", "submitted", "running", "finished", "failed", "canceled", "interrupted"))) {
10281028
action <- getOption("future.state.onInvalid", "warning")
10291029

10301030
if (action != "ignore") {

R/backend_api-UniprocessFuture-class.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ UniprocessFuture <- function(expr = NULL, substitute = TRUE, envir = parent.fram
2323
run.UniprocessFuture <- function(future, ...) {
2424
debug <- isTRUE(getOption("future.debug"))
2525

26-
if (future[["state"]] != 'created') {
26+
if (future[["state"]] != "created") {
2727
label <- sQuoteLabel(future)
2828
stop(FutureError(sprintf("A future (%s) can only be launched once", label), future = future))
2929
}
@@ -33,10 +33,10 @@ run.UniprocessFuture <- function(future, ...) {
3333
assertOwner(future)
3434

3535
## Run future
36-
future[["state"]] <- 'running'
36+
future[["state"]] <- "running"
3737
data <- getFutureData(future, debug = debug)
3838
future[["result"]] <- evalFuture(data)
39-
future[["state"]] <- 'finished'
39+
future[["state"]] <- "finished"
4040

4141
if (debug) mdebugf("%s started (and completed)", class(future)[1])
4242

R/core_api-cancel.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ cancel.Future <- function(x, interrupt = TRUE, ...) {
8585
on.exit(mdebug_pop())
8686
}
8787

88-
## Only running futures can be canceled, ignore everything else
89-
if (future[["state"]] != "running") {
90-
if (debug) mdebug("Skipping, because a non-running future")
88+
## Only submitted or running futures can be canceled, ignore everything else
89+
if (!future[["state"]] %in% c("submitted", "running")) {
90+
if (debug) mdebug("Skipping, because not a submitted or a running future")
9191
return(invisible(future))
9292
}
9393

R/core_api-reset.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ reset.environment <- function(x, ...) {
6565
reset.Future <- function(x, ...) {
6666
future <- x
6767

68-
if (future[["state"]] == "running") {
68+
if (future[["state"]] %in% c("submitted", "running")) {
69+
msg <- sprintf("Cannot reset a %s future", future[["state"]])
6970
backend <- future[["backend"]]
7071
if (!inherits(backend, "FutureBackend")) {
71-
warning(FutureWarning("Cannot reset a running future", future = future))
72+
warning(FutureWarning(msg, future = future))
7273
return(future)
7374
}
74-
stop(FutureError("Cannot reset a running future", future = future))
75+
stop(FutureError(msg, future = future))
7576
}
7677

7778
core_fields <- c(

R/core_api-value.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ value.list <- function(x, idxs = NULL, recursive = 0, reduce = NULL, stdout = TR
659659
## so that future can be resolved in the asynchronously
660660
if (inherits(obj, "Future")) {
661661
## Lazy future that is not yet launched?
662-
if (obj[["state"]] == 'created') obj <- run(obj)
662+
if (obj[["state"]] == "created") obj <- run(obj)
663663

664664
if (!resolved(obj)) {
665665
next

R/protected_api-resolve.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ resolve.Future <- function(x, idxs = NULL, recursive = 0, result = FALSE, stdout
9292
result <- result || relay
9393

9494
## Lazy future that is not yet launched?
95-
if (future[["state"]] == 'created') future <- run(future)
95+
if (future[["state"]] == "created") future <- run(future)
9696

9797
## Poll for the Future to finish
9898
while (!resolved(future)) {
@@ -251,7 +251,7 @@ resolve.list <- function(x, idxs = NULL, recursive = 0, result = FALSE, stdout =
251251
## so that future can be resolved in the asynchronously
252252
if (inherits(obj, "Future")) {
253253
## Lazy future that is not yet launched?
254-
if (obj[["state"]] == 'created') obj <- run(obj)
254+
if (obj[["state"]] == "created") obj <- run(obj)
255255
if (!resolved(obj)) next
256256
if (debug) mdebugf("Future #%d", ii)
257257
if (result) {
@@ -397,7 +397,7 @@ resolve.environment <- function(x, idxs = NULL, recursive = 0, result = FALSE, s
397397
## so that future can be resolved in the asynchronously
398398
if (inherits(obj, "Future")) {
399399
## Lazy future that is not yet launched?
400-
if (obj[["state"]] == 'created') obj <- run(obj)
400+
if (obj[["state"]] == "created") obj <- run(obj)
401401
if (!resolved(obj)) next
402402
if (debug) mdebugf("Future #%d", ii)
403403
if (result) value(obj, stdout = FALSE, signal = FALSE)
@@ -543,7 +543,7 @@ resolve.listenv <- function(x, idxs = NULL, recursive = 0, result = FALSE, stdou
543543
## so that future can be resolved in the asynchronously
544544
if (inherits(obj, "Future")) {
545545
## Lazy future that is not yet launched?
546-
if (obj[["state"]] == 'created') obj <- run(obj)
546+
if (obj[["state"]] == "created") obj <- run(obj)
547547
if (!resolved(obj)) next
548548
if (debug) mdebugf("Future #%d", ii)
549549
if (result) value(obj, stdout = FALSE, signal = FALSE)

0 commit comments

Comments
 (0)