-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with forked (multicore) code in ark #3817
Comments
I can reproduce this problem only in Positron (the code runs fine in RStudio). Here is the full traceback:
|
Minimal reprex fn <- function(i) {
if (i == 3) {
cat("hiya")
}
i
}
parallel::mclapply(
X = 1:10,
FUN = fn,
mc.cores = 5
)
Something about > fn <- function(i) {
- if (i == 3) {
- cat("hiya")
- }
- i
- }
-
- parallel::mclapply(
- X = 1:10,
- FUN = fn,
- mc.cores = 5
- )
Warning message:
In parallel::mclapply(X = 1:10, FUN = fn, mc.cores = 5) :
scheduled core 3 did not deliver a result, all values of the job will be affected
[[1]]
[1] 1
[[2]]
[1] 2
[[3]]
NULL
[[4]]
[1] 4
[[5]]
[1] 5
[[6]]
[1] 6
[[7]]
[1] 7
[[8]]
NULL
[[9]]
[1] 9
[[10]]
[1] 10 |
This may be anticipated but when I render a reprex it behaves as expected fn <- function(i) {
if (i == 3) {
cat("hiya")
}
i
}
parallel::mclapply(
X = 1:10,
FUN = fn,
mc.cores = 5
)
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 2
#>
#> [[3]]
#> [1] 3
#>
#> [[4]]
#> [1] 4
#>
#> [[5]]
#> [1] 5
#>
#> [[6]]
#> [1] 6
#>
#> [[7]]
#> [1] 7
#>
#> [[8]]
#> [1] 8
#>
#> [[9]]
#> [1] 9
#>
#> [[10]]
#> [1] 10 Created on 2024-07-03 with reprex v2.1.0 Wheareas outside of a reprex I get the same error as Davis |
I think it is going to be very unsafe to use forked (multicore) code in ark, at least until we can take a closer look at this and see if it is even possible to do this safely. It is highly likely that forking is going to interfere with the way that we communicate to our frontends through Jupyter comms. The It should be safe to use multi-process parallelism, i.e. PSOCK clusters created with R docs in
And I know RStudio has been fighting issues like this for a long time |
@joshuafayallen if you control the call to mcreplicate and set # doesnt work
mcreplicate::mc_replicate(
n = 5,
expr = 1 + 1,
mc.cores = 5
)
# works
mcreplicate::mc_replicate(
n = 5,
expr = 1 + 1,
mc.cores = 5,
refresh = FALSE
) |
@DavisVaughan Thank you so much! |
Yeah reprex takes this off to an entirely separate process, so it's a totally different exercise, even when the reprex-ing happens in Positron. |
@jennybc Yeah that makes sense. After spending a few hours when I went to render the reprex I thought I was losing my mind |
Is there any hope of supporting this in ark via things like https://docs.rs/libc/latest/libc/fn.pthread_atfork.html to close the relevant communication channels in forked sub-processes? RStudio does something somewhat similar; we try to keep track of which process is the "main" process after a fork occurs, and let "child" processes continue execution but forbid certain things that only the main process should do. |
Or use the atfork hook to fail/crash with a proper error message? I'd be tempted to only support truly cross-platform and well specified approaches in ark. R can always be invoked in a separate process if fork-parallelism is needed. |
Positron Version:
Positron Version: 2024.06.1 (Universal) build 27
Code - OSS Version: 1.90.0
Commit: a893e5b
Date: 2024-06-26T02:08:06.673Z
Electron: 29.4.0
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Darwin arm64 23.5.0
Steps to reproduce the issue:
Hi all I am not sure if this is just an issue on my end. But I was doing some analysis and kept running into a peculiar issue. For whatever reason positron keeps giving me an error. Whereas Vscode running radian does not.
What did you expect to happen?
Created on 2024-07-02 with reprex v2.1.0
Were there any error messages in the output or Developer Tools console?
Error in
bootstrap_sample()
:! 'list' object cannot be coerced to type 'double'
Hide Traceback
▆
The text was updated successfully, but these errors were encountered: