Skip to content

callr not working with nested loops #27

Open
@jestover

Description

@jestover
library(furrr)
library(callr)

inner_loop <- function(x){future_map_dbl(x, ~ .x)}
outer_loop <- function(x){future_map(x, ~ inner_loop(.x))}
x <- list(1:10, 11:20, 21:30, 31:40)

plan(sequential)
outer_loop(x)
[[1]]
 [1]  1  2  3  4  5  6  7  8  9 10

[[2]]
 [1] 11 12 13 14 15 16 17 18 19 20

[[3]]
 [1] 21 22 23 24 25 26 27 28 29 30

[[4]]
 [1] 31 32 33 34 35 36 37 38 39 40

plan(list(tweak(multisession, workers = 2), tweak(multisession, workers = 2)))
outer_loop(x)
[[1]]
 [1]  1  2  3  4  5  6  7  8  9 10

[[2]]
 [1] 11 12 13 14 15 16 17 18 19 20

[[3]]
 [1] 21 22 23 24 25 26 27 28 29 30

[[4]]
 [1] 31 32 33 34 35 36 37 38 39 40

plan(list(tweak(callr, workers = 2), tweak(callr, workers = 2)))
outer_loop(x)
Error in (function (.x, .f, ..., .progress = FALSE)  : 
  ℹ In index: 1.
Caused by error:
! object '...furrr_map_fn' not found

plan(list(tweak(callr, workers = 2), tweak(multisession, workers = 2)))
outer_loop(x)
Error in (function (.x, .f, ..., .progress = FALSE)  : 
  ℹ In index: 1.
Caused by error:
! object '...furrr_map_fn' not found

plan(callr(workers = 2))
outer_loop(x)
Error in (function (.x, .f, ..., .progress = FALSE)  : 
  ℹ In index: 1.
Caused by error in `vctrs::vec_c()`:
! Can't convert `..1` <list> to <double>.

plan(list(tweak(multisession, workers = 2), tweak(callr, workers = 2)))
outer_loop(x)
[[1]]
 [1]  1  2  3  4  5  6  7  8  9 10

[[2]]
 [1] 11 12 13 14 15 16 17 18 19 20

[[3]]
 [1] 21 22 23 24 25 26 27 28 29 30

[[4]]
 [1] 31 32 33 34 35 36 37 38 39 40

I ran this example on a 2023 MacBook Pro, but I originally discovered the issue running some code on a Linux server. The real code is a cross validation exercise on some large textual data. I kept running into a problem where the memory usage just continuously grows over time, so I switched to the callr backend to try to address the memory issue, but I keep running into other problems. This was the first that I was able to replicate on a small reproducible example. Let me know if there is any other useful information I can provide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions