Skip to content

Commit

Permalink
Improve handling of dots arguments at daemons() (#156)
Browse files Browse the repository at this point in the history
* drop wrong type of dots arguments rather than error

* add regression tests
  • Loading branch information
shikokuchuo committed Sep 16, 2024
1 parent 1c83562 commit 9a3c180
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mirai
Type: Package
Title: Minimalist Async Evaluation Framework for R
Version: 1.2.0.9016
Version: 1.2.0.9017
Description: Designed for simplicity, a 'mirai' evaluates an R expression
asynchronously in a parallel process, locally or distributed over the
network, with the result automatically available upon completion. Modern
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# mirai 1.2.0.9016 (development)
# mirai 1.2.0.9017 (development)

* `daemons(dispatcher = NA)` now provides access to threaded dispatcher (experimental). This implements dispatcher using a thread rather than an external process and is faster and more efficient.
* `daemons()` behavioural changes:
- Return value is now always an integer value - either the number of daemons set if using dispatcher, or the number of daemons launched locally (zero if using a remote launcher).
- Gains argument 'force' to control whether calls to `daemons()` resets previous settings for the same compute profile.
- Invalid type of '...' arguments are now dropped instead of throwing an error. This allows '...' containing unused arguments to be more easily passed from other functions.
* `mirai_map()` behavioural changes:
- Combining multiple collection options becomes easier, allowing for instance `x[.stop, .progress]`.
- Adds `mirai_map()[.progress_cli]` as an alternative progress indicator, using the 'cli' package to show % complete and ETA.
Expand Down
5 changes: 2 additions & 3 deletions R/daemons.R
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,9 @@ req_socket <- function(url, tls = NULL, resend = 0L)
`opt<-`(socket(protocol = "req", listen = url, tls = tls), "req:resend-time", resend)

parse_dots <- function(...) {
missing(...) && return("")
...length() || return("")
dots <- list(...)
for (dot in dots)
is.numeric(dot) || is.logical(dot) || stop(._[["wrong_dots"]], call. = FALSE)
dots <- dots[as.logical(lapply(dots, function(x) is.numeric(x) | is.logical(x)))]
dnames <- names(dots)
out <- sprintf(",%s", paste(dnames, dots, sep = "=", collapse = ","))
pos <- dnames == "output"
Expand Down
3 changes: 1 addition & 2 deletions R/mirai-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@
requires_local = "ssh_config(): SSH tunnelling requires 'url' hostname to be '127.0.0.1' or 'localhost'",
single_url = "only one 'url' should be specified",
sync_timeout = "initial sync with dispatcher/daemon timed out after 10s",
url_spec = "launch_*(): numeric value for 'url' is out of bounds",
wrong_dots = "daemons(): '...' arguments should only be of integer, numeric or logical type"
url_spec = "launch_*(): numeric value for 'url' is out of bounds"
),
hash = TRUE
)
Expand Down
9 changes: 4 additions & 5 deletions tests/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ nanotesterr(daemons(url = "URL"), "Invalid argument")
nanotesterr(daemons(-1), "zero or greater")
nanotesterr(daemons(n = 0, url = "ws://localhost:0"), "1 or greater")
nanotesterr(daemons(raw(0L)), "must be numeric")
nanotesterr(daemons(n = 1, maxtasks = "100"), "'...' arguments")
nanotesterr(dispatcher(client = "URL"), "at least one")
nanotesterr(daemon("URL"), "Invalid argument")
nanotest(is.character(mlc <- launch_remote("ws://[::1]:5555")))
Expand Down Expand Up @@ -196,7 +195,7 @@ connection && {
# advanced daemons and dispatcher tests
connection && .Platform[["OS.type"]] != "windows" && Sys.getenv("NOT_CRAN") == "true" && {
Sys.sleep(1L)
nanotesto(daemons(url = local_url(), dispatcher = TRUE))
nanotesto(daemons(url = local_url(), dispatcher = TRUE, notused = "wrongtype"))
nanotest(grepl("://", launch_remote(1L), fixed = TRUE))
nanotestn(launch_local(nextget("urls")))
Sys.sleep(1L)
Expand All @@ -212,9 +211,9 @@ connection && .Platform[["OS.type"]] != "windows" && Sys.getenv("NOT_CRAN") == "
}
Sys.sleep(1L)
nanotestz(daemons(NULL))
nanotesto(daemons(url = "ws://:0", token = TRUE))
nanotesto(daemons(url = "ws://:0", correctype = 0L, token = TRUE))
nanotestz(daemons(0L))
nanotestz(with(daemons(url = "tcp://:0", token = TRUE), {8L - 9L + 1L}))
nanotestz(with(daemons(url = "tcp://:0", correcttype = 1, token = TRUE), {8L - 9L + 1L}))
nanotest(daemons(n = 2, "ws://:0") == 2L)
nanotest(is.integer(nextget("pid")))
nanotest(length(nextget("urls")) == 2L)
Expand All @@ -237,7 +236,7 @@ connection && .Platform[["OS.type"]] != "windows" && Sys.getenv("NOT_CRAN") == "
nanotest(is.character(saisei(i = 1L, force = TRUE)))
nanotestn(saisei(i = 10L))
nanotestz(daemons(0))
nanotest(daemons(n = 2, "tcp://127.0.0.1:45555") == 2L)
nanotest(daemons(n = 2, "tcp://127.0.0.1:45555", correcttype = NA) == 2L)
Sys.sleep(1L)
nanotestn(launch_local(nextget("urls", .compute = "default")[1L], maxtasks = 1L))
nanotestn(launch_local(2, maxtasks = 1L))
Expand Down

0 comments on commit 9a3c180

Please sign in to comment.