From 0d85ac296fdb331110a8e132ca0bbaa7f069c40d Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:13:17 +0000 Subject: [PATCH 1/2] daemon() records initial state of global environment --- DESCRIPTION | 2 +- NEWS.md | 3 ++- R/daemon.R | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ceb8b1fd8..40a2ea7c4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: mirai Type: Package Title: Minimalist Async Evaluation Framework for R -Version: 0.11.3.9002 +Version: 0.11.3.9003 Description: Lightweight parallel code execution and distributed computing. Designed for simplicity, a 'mirai' evaluates an R expression asynchronously, on local or network resources, resolving automatically upon completion. diff --git a/NEWS.md b/NEWS.md index 59f987342..eb4194c88 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,8 @@ -# mirai 0.11.3.9002 (development) +# mirai 0.11.3.9003 (development) * Adds `local_url()` helper to construct a random inter-process communications URL for local daemons (thanks @noamross #90). * `daemon()` argument 'autoexit' now accepts a signal value such as `tools::SIGINT` in order to raise it upon exit. +* `daemon()` now records the state of initial global environment objects (e.g. those created in .Rprofile) for cleanup purposes (thanks @noamross #91). * Eliminates potential memory leaks along certain error paths. * Requires nanonext >= [0.11.0.9001]. diff --git a/R/daemon.R b/R/daemon.R index 27e6a52d2..827c388fe 100644 --- a/R/daemon.R +++ b/R/daemon.R @@ -132,7 +132,7 @@ daemon <- function(url, autoexit = TRUE, cleanup = TRUE, output = FALSE, close(devnull) }, add = TRUE) } - `[[<-`(`[[<-`(`[[<-`(., "op", .Options), "se", search()), "vars", ".Random.seed") + `[[<-`(`[[<-`(`[[<-`(., "op", .Options), "se", search()), "vars", names(.GlobalEnv)) count <- 0L start <- mclock() From e9cdab9182c37bebe35fc51d9c6cc008bde32b26 Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Fri, 29 Dec 2023 10:03:48 +0000 Subject: [PATCH 2/2] use snapshot() --- R/daemon.R | 5 ++++- R/mirai.R | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/R/daemon.R b/R/daemon.R index 827c388fe..d9330796e 100644 --- a/R/daemon.R +++ b/R/daemon.R @@ -132,7 +132,7 @@ daemon <- function(url, autoexit = TRUE, cleanup = TRUE, output = FALSE, close(devnull) }, add = TRUE) } - `[[<-`(`[[<-`(`[[<-`(., "op", .Options), "se", search()), "vars", names(.GlobalEnv)) + snapshot() count <- 0L start <- mclock() @@ -212,3 +212,6 @@ perform_cleanup <- function(cleanup) { if (cleanup[3L]) options(.[["op"]]) if (cleanup[4L]) gc(verbose = FALSE) } + +snapshot <- function() `[[<-`(`[[<-`(`[[<-`(., "op", .Options), "se", search()), "vars", names(.GlobalEnv)) + diff --git a/R/mirai.R b/R/mirai.R index c2537c63f..1e604d6d7 100644 --- a/R/mirai.R +++ b/R/mirai.R @@ -460,8 +460,6 @@ mk_mirai_error <- function(e) { `class<-`(msg, c("miraiError", "errorValue", "try-error")) } -snapshot <- function() `[[<-`(`[[<-`(`[[<-`(., 'vars', names(.GlobalEnv)), 'se', search()), 'op', .Options) - .interrupt_error <- `class<-`("", c("miraiInterrupt", "errorValue", "try-error")) .snapshot <- expression(mirai:::snapshot()) .timedelay <- expression(nanonext::msleep(500L))