Skip to content

Commit def8295

Browse files
BUG FIX: plan(cluster, workers = parallelly::makeClusterSequential()) would erase the global environment as soon as a future is launched
1 parent 3bd80a1 commit def8295

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
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.68.0-9035
2+
Version: 1.68.0-9036
33
Title: Unified Parallel and Distributed Processing in R for Everyone
44
Depends:
55
R (>= 3.2.0)

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Version (development version)
22

3-
## Signifcant Changes
3+
## Significant Changes
44

55
* Removed generic function `as.cluster()`, which has been re-exported
66
from the **parallelly** package since 2020. If needed, please use
@@ -26,6 +26,9 @@
2626
1 unknown future arguments: 'interrupts'" for third-party future
2727
backends.
2828

29+
* `plan(cluster, workers = parallelly::makeClusterSequential())` would
30+
erase the global environment as soon as a future is launched.
31+
2932
* `resolved()` on a 'cluster' future would produce a warning when
3033
using a `parallelly::makeClusterSequential())` cluster.
3134

R/backend_api-11.ClusterFutureBackend-class.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,11 @@ launchFuture.ClusterFutureBackend <- function(backend, future, ...) {
283283
## may happen even if the future is evaluated inside a
284284
## local, e.g. local({ a <<- 1 }).
285285
## If the persistent = TRUE, this will be skipped.
286+
##
287+
## SPECIAL CASE: Do not erase if a
288+
## parallelly::makeClusterSequential() is used
286289
persistent <- isTRUE(future[["persistent"]])
287-
if (!persistent) {
290+
if (!persistent && !inherits(node, "sequential_node")) {
288291
if (debug) mdebug_push("eraseGlobalEnvironment() ...")
289292

290293
t_start <- Sys.time()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
if (getRversion() >= "4.4.0") {
2+
library(future)
3+
options(future.debug = FALSE)
4+
5+
message("plan(cluster, workers = parallelly::makeClusterSequential()) ...")
6+
cl <- parallelly::makeClusterSequential()
7+
print(cl)
8+
plan(cluster, workers = cl)
9+
print(plan())
10+
11+
message("future(42)")
12+
f <- future(42)
13+
v <- value(f)
14+
print(v)
15+
stopifnot(v == 42)
16+
17+
message("future(2 * a, lazy = TRUE)")
18+
a <- 42
19+
f <- future(2 * a, lazy = TRUE)
20+
rm(a)
21+
v <- value(f)
22+
print(v)
23+
stopifnot(v == 2 * 42)
24+
25+
message("future(2 * a)")
26+
a <- 42
27+
f <- future(2 * a)
28+
v <- value(f)
29+
print(v)
30+
stopifnot(v == 2 * a)
31+
32+
plan(sequential)
33+
}

0 commit comments

Comments
 (0)