我怎样才能优雅地关闭Rserve?

use*_*398 13 r rserve

我在Mac和Ubuntu中尝试了很多选项.我阅读了Rserve文档

http://rforge.net/Rserve/doc.html
Run Code Online (Sandbox Code Playgroud)

以及Rserve和RSclient包的内容:

http://cran.r-project.org/web/packages/RSclient/RSclient.pdf

http://cran.r-project.org/web/packages/Rserve/Rserve.pdf

我无法弄清楚在Rserve中打开/关闭连接以及正常关闭Rserve的正确工作流程是什么.

例如,在Ubuntu中,我使用./config --enable-R-shlib(遵循Rserve文档)从源代码安装了R,并在/etc/Rserve.conf中添加了"control enable"行.

在Ubuntu终端中:

library(Rserve)
library(RSclient)
Rserve()
c<-RS.connect()
c ## this is an Rserve QAP1 connection

## Trying to shutdown the server
RSshutdown(c) 
Error in writeBin(as.integer....): invalid connection

RS.server.shutdown(c)
Error in RS.server.shutdown(c): command failed with satus code 0x4e: no control line present   (control commands disabled or server shutdown)
Run Code Online (Sandbox Code Playgroud)

但是,我可以关闭连接:

RS.close(c)
>NULL
c ## Closed Rserve connection
Run Code Online (Sandbox Code Playgroud)

关闭连接后,我也尝试了选项(即使连接已关闭,也尝试使用参数'c'):

RS.server.shutdown()
RSshutdown()
Run Code Online (Sandbox Code Playgroud)

所以,我的问题是:

1-如何优雅地关闭Rserve?

2-没有RSclient可以使用Rserve吗?

我也看了看

如何关闭Rserve(),在DEBUG中运行

但问题是调试模式,也没有解决.(我没有足够的声誉来评论/询问关闭是否在非调试模式下工作).

还看了看:

如何使用R客户端连接到Rserve

非常感谢!

zhe*_*elt 17

加载Rserve和RSclient包,然后连接到实例.

> library(Rserve)
> library(RSclient)

> Rserve(port = 6311, debug = FALSE)
> Rserve(port = 6312, debug = TRUE)

Starting Rserve...
 "C:\..\Rserve.exe" --RS-port 6311
Starting Rserve...
 "C:\..\Rserve_d.exe" --RS-port 6312 

> rsc <- RSconnect(port = 6311)
> rscd <- RSconnect(port = 6312)
Run Code Online (Sandbox Code Playgroud)

看起来他们正在运行......

> system('tasklist /FI "IMAGENAME eq Rserve.exe"')
> system('tasklist /FI "IMAGENAME eq Rserve_d.exe"')

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
Rserve.exe                    8600 Console                    1     39,312 K
Rserve_d.exe                 12652 Console                    1     39,324 K
Run Code Online (Sandbox Code Playgroud)

让我们关闭他们.

> RSshutdown(rsc)
> RSshutdown(rscd)
Run Code Online (Sandbox Code Playgroud)

他们走了......

> system('tasklist /FI "IMAGENAME eq Rserve.exe"')
> system('tasklist /FI "IMAGENAME eq Rserve_d.exe"')

INFO: No tasks are running which match the specified criteria.
Run Code Online (Sandbox Code Playgroud)

通过使用args和/或配置脚本启动Rserve,可以使用无RSclient.然后,您可以从其他程序(如Tableau)或您自己的代码连接到它.RSclient提供了一种将命令/数据从R实例传递给Rserve的方法.

希望这可以帮助 :)


mee*_*ram 5

在 Windows 系统中,如果要关闭RServe实例,可以使用systemin 函数R将其关闭。例如在R

library(Rserve)
Rserve() # run without any arguments or ports specified
system('tasklist /FI "IMAGENAME eq Rserve.exe"') # run this to see RServe instances and their PIDs
system('TASKKILL /PID {yourPID} /F') # run this to kill off the RServe instance with your selected PID
Run Code Online (Sandbox Code Playgroud)

如果您使用该 PID 正确关闭了 RServe 实例,则会出现以下消息:

成功:PID 为 xxxx 的进程已终止。

您可以通过输入检查 RServe 实例是否已关闭

system('tasklist /FI "IMAGENAME eq Rserve.exe"')

再次。如果不再有 RServe 实例在运行,您将收到消息

信息:没有运行符合指定条件的任务。

此相关问题中可以看到有关此主题的更多帮助和信息。

请注意,前面的答案中提到的“RSClient”方法比这个方法更整洁、更容易,但无论如何我还是为那些开始RServe而不知道如何停止它的人提出了它。