Spawned processes not being shut down when running multiple chains in Rstudio

This is a problem we had awhile ago, then I thought it got fixed, but it’s been happening again.

Here’s what happened: I ran Stan with 4 chains in Rstudio. It was running and I stopped it in the middle. But the 4 chains kept running in the background. I had to go to the Activity Monitor and shut them down one at a time by hand.

I’ve encountered this occasionally as well, which is one of the reasons I made ezStan, which has a kill_stan() function for killing wayward chains. Note, however, that all kill_stan() does is run the unix command killall R, so it will kill any R sessions being run from the command line.

BTW, you might like the alternative interface that start_stan() provides whereby running chains doesn’t lock up your primary R session; you can check in on sampling progress any time by running watch_stan(), which you can either kill with ctrl-c (or clicking stop in the Console UI) or leave running until sampling is done (with an alert sound if you have the beepr package installed). In addition to slightly prettier progress indicators, watch_stan() shows if divergences have been encountered and gives you the option to automatically run kill_stan() if this happens. I’m working on adding more pre- and post-warmup diagnostics to compute & present during sampling as well.

3 Likes

I think this was addressed in a Rstudio update last year: https://blog.rstudio.com/2018/10/16/rstudio-1-2-preview-stan/

Worker Interruption
One aspect that had previously made working with Stan in RStudio frustrating was the inability to interrupt parallel Stan workers. This implied that attempts to fit a computationally expensive model could not be interrupted, and the only remedy previously was to restart the IDE or forcefully shut down the workers through another mechanism.

We’re very happy to share that this limitation has been lifted with RStudio v1.2. Now, when fitting a Stan model with parallel workers, you can interrupt the workers as you would any regular R code – either use the Escape key, or press the Stop button in the Console pane.

Yes, I remember that from last year and I think the problem was fixed for awhile. But now it’s returned.