Skip to content
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

Callback registries should be cleared when process is forked #142

Open
wch opened this issue Dec 8, 2020 · 0 comments
Open

Callback registries should be cleared when process is forked #142

wch opened this issue Dec 8, 2020 · 0 comments

Comments

@wch
Copy link
Member

wch commented Dec 8, 2020

This is a follow-up to #141.

When the R process is forked with future, the child process gets a copy of the event loop, but it should be cleared out in the child process.

Example:

library(later)
library(future)

# Enable forked process
options(future.fork.enable = TRUE)
plan(multicore, workers = 2)

ff <- function(){
  message( Sys.getpid())
  later::later(ff, 2)
}
ff()

fs <- replicate(2, {
  future({
    for (i in 1:1000) {
      later::run_now(timeout = 1)
    }
  })
})

This will output:

18235
18241
18242
18235
18241
18242
...

The callback registries should be cleared out when the process is forked. However, we have to be careful about how we do this. What happens if the fork happens in the middle of executing a callback? Is it safe to clear out the C++ data structures at any time that a fork could happen? (Normally the callbacks are removed after being executed.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant