Skip to content

Commit 2c9351b

Browse files
Interrupted futures are now reset to vanilla, lazy futures + all launched futures has a reference to their FutureBackend
1 parent 5a96a10 commit 2c9351b

8 files changed

+59
-2
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future
2-
Version: 1.34.0-9302
2+
Version: 1.34.0-9303
33
Title: Unified Parallel and Distributed Processing in R for Everyone
44
Imports:
55
digest,

NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ S3method(print,FutureStrategy)
5353
S3method(print,FutureStrategyList)
5454
S3method(print,future)
5555
S3method(print,sessionDetails)
56+
S3method(resetFuture,FutureBackend)
5657
S3method(resetWorkers,default)
5758
S3method(resetWorkers,multicore)
5859
S3method(resolve,Future)
@@ -149,6 +150,7 @@ export(multisession)
149150
export(nbrOfFreeWorkers)
150151
export(nbrOfWorkers)
151152
export(plan)
153+
export(resetFuture)
152154
export(resetWorkers)
153155
export(resolve)
154156
export(resolved)

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
* Interrupted futures are now handled and produce an informative warning.
2222

23+
* Interrupted futures are reset of vanilla, lazy futures. This way
24+
interrupted futures can be re-evaluated again, for instance, on
25+
another future backend.
26+
2327
## Bug Fixes
2428

2529
* Now 'interrupt' conditions are captured during the evaluation of

R/backend_api-Future-class.R

+1
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ run.Future <- function(future, ...) {
444444
class(future) <- backend[["futureClasses"]]
445445

446446
if (debug) mdebug(" - Launching futures ...")
447+
future[["backend"]] <- backend
447448
future2 <- launchFuture(backend, future = future)
448449
if (debug) mdebug(" - Launching futures ... done")
449450
if (debug) mdebug(" - Future launched: ", commaq(class(future2)))

R/backend_api-FutureBackend-class.R

+43
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,49 @@ launchFuture.FutureBackend <- function(backend, future, ...) {
4747
}
4848

4949

50+
#' @rdname FutureBackend
51+
#' @export
52+
resetFuture <- function(backend, future, ...) {
53+
UseMethod("resetFuture")
54+
}
55+
56+
57+
#' @export
58+
resetFuture.FutureBackend <- function(backend, future, ...) {
59+
core_fields <- c(
60+
"version",
61+
"expr",
62+
"envir",
63+
"stdout",
64+
"conditions",
65+
"globals",
66+
"packages",
67+
"seed",
68+
"lazy",
69+
"asynchronous",
70+
"local",
71+
"reset",
72+
"label",
73+
"earlySignal",
74+
"gc",
75+
"onReference",
76+
"calls",
77+
"state"
78+
)
79+
class(future) <- "Future"
80+
81+
drop <- setdiff(names(future), core_fields)
82+
for (name in drop) {
83+
future[[name]] <- NULL
84+
}
85+
86+
future[["state"]] <- "created"
87+
future[["lazy"]] <- TRUE
88+
89+
future
90+
}
91+
92+
5093
makeFutureBackend <- function(evaluator, ...) {
5194
backend <- attr(evaluator, "backend")
5295

R/backend_api-SequentialFutureBackend-class.R

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ launchFuture.SequentialFutureBackend <- function(backend, future, ...) {
7272
split <- backend[["split"]]
7373
if (!is.null(split)) data[["capture"]][["split"]] <- split
7474

75+
future[["backend"]] <- backend
76+
7577
## Inherit 'earlySignal' from backend?
7678
earlySignal <- backend[["earlySignal"]]
7779
if (!is.null(earlySignal)) future[["earlySignal"]] <- earlySignal

R/protected_api-signalConditions.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ signalConditions <- function(future, include = "condition", exclude = NULL, resi
102102
source <- attr(session_uuid, "source")
103103
host <- source[["host"]]
104104
pid <- source[["pid"]]
105-
msg <- sprintf("A future ('%s') of class %s was interrupted at %s, while running on %s (pid %s)", label, class(future)[1], format(when, format = "%FT%T"), sQuote(host), pid)
105+
msg <- sprintf("A future ('%s') of class %s was interrupted at %s, while running on %s (pid %s). The future was reset to a vanilla, lazy future, which can be re-evaluted again", label, class(future)[1], format(when, format = "%FT%T"), sQuote(host), pid)
106+
backend <- future[["backend"]]
107+
if (!is.null(backend)) future <- resetFuture(backend, future)
106108
warning(FutureInterruptWarning(msg, future = future))
107109
} else if (inherits(condition, "warning")) {
108110
warning(condition)

man/FutureBackend.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)