rstudio / httpuv

HTTP and WebSocket server package for R
Other
229 stars 86 forks source link

How to keep server alive when using startServer() and RScript #307

Closed tconwell closed 3 years ago

tconwell commented 3 years ago

Using RScript to run a script that starts a server using startServer() will start the server and immediately end the R session when done, thereby killing the server. Is there a way to start a server with httpuv and RScript that both returns and doesn't immediately kill the server after creating it?

wch commented 3 years ago

You should be able to do something like this:

while(TRUE) {
  httpuv::service()
}

You can of course substitute the TRUE with some other condition for exiting the application. As written, you would need to interrupt the application with Ctrl-C.

wch commented 3 years ago

Oh, I also just remembered that you can simply use runServer() instead of startServer(), and it will run the application and the process will stay alive. If you call runServer(), you'll have to send an interrupt to exit the application.