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

Call the callback function at a specific call stack depth? #152

Open
Jiefei-Wang opened this issue Aug 2, 2021 · 0 comments
Open

Call the callback function at a specific call stack depth? #152

Jiefei-Wang opened this issue Aug 2, 2021 · 0 comments

Comments

@Jiefei-Wang
Copy link

Jiefei-Wang commented Aug 2, 2021

Hi, I'm a developer of a parallel backend package and looking for a way to call a function after a specific time period in the worker, so it can give me the chance to check the manager's status and interrupt the long-running task if needed. I did a little search and found your package is very interesting and related. I see that the callback only works at the top-level prompt, but in my case, the worker must be trapped in an infinite loop so the top-level prompt is not reachable. Here is an illustrative example for the worker

start_worker <- function(){
    while(TRUE){
        ## receive the job from the manager
        task <- receive()
        ## run the task
        ## need to check the manager's status when running the task
        result <- exec(task)
        ## send the result back
        send(result)
    }
}

Once the worker has been started, it will never return the control to the user, so there is no way to make the callback work in this case. However, I see in your document the reason for only calling the callback at the top level is for avoiding bugs due to reentrancy. This makes me wonder whether it is possible to call the callback at a specific call stack level if I know it is safe to call(e.g. only call the callback when the call stack is start_worker -> exec), or is it totally impossible due to the restriction of the R language? Could you please shed some light on this question? Any suggestion will be appreciated!

Best,
Jiefei

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