0

本地系统:OSX 10.10.3 Yosemite Python 2.7

远程服务器:NAME="Amazon Linux AMI" VERSION="2014.09"

我正在尝试使用 Python 启动(重新启动)服务器上的 Rserve 进程。我可以直接以 ec2 用户身份启动它($R CMD Rserve --vanilla)或使用 SystemV 脚本($service Rserve restart)...但是 Python 脚本仍然挂起,等待启动的 Rserve 进程完成. 因为它是一个守护进程,所以它没有完成并且脚本挂起。

我已经尝试过 subprocess.call 和 subprocess Popen。

log.error('Attempting to restart Rserve environment...')
PEM  = "/Users/xxx/ra.pem"
USER = "ec2-user"
PORT = '22'
SERVER = str(callobj.rhandler_host) # ends up confirmed correct IP
command = ['/sbin/service', 'Rserve', 'restart'] # Starts Rserve and hangs
# command = ['R', 'CMD', 'Rserve', '--vanilla'] # Starts Rserve and hangs
# command = ['ls'] # lists and finishes

ssh = ['ssh', '-i', PEM, '-p', PORT, USER + '@' + SERVER]
run = ssh + command

proc = subprocess.Popen(run, shell=False, 
#                         stdout=subprocess.PIPE) # Tried this, no change 
                          stdin=None, stdout=None, stderr=None, close_fds=True)

输出:

2015-06-06 16:51:51,362 - MRATrefactor - ERROR - [R] environment does not appear to be running on server '54.xxx.xxx.x2'. Connection denied, server not reachable or not accepting connections
2015-06-06 16:51:51,363 - MRATrefactor - ERROR - rserveHandler.connect: ; *args: None; **kwargs: None; RserveNotRunning: [R] environment does not appear to be running on server '54.xxx.xxx.x2'. Connection denied, server not reachable or not accepting connections. Rserve may not be running.
2015-06-06 16:51:51,363 - MRATrefactor - ERROR - Attempting to restart Rserve environment...
    PID: 8205
    Cannot match 8205 to running processes.
    Grepping for process [expecting PID: 8205]...

    grep count: 0
    0
    Stopping Rserve:  [FAILED]
    Starting Rserve: 
    R version 3.1.1 (2014-07-10) -- "Sock it to Me"
    Copyright (C) 2014 The R Foundation for Statistical Computing
    Platform: x86_64-redhat-linux-gnu (64-bit)

    R is free software and comes with ABSOLUTELY NO WARRANTY.
    You are welcome to redistribute it under certain conditions.
    Type 'license()' or 'licence()' for distribution details.

    Natural language support but running in an English locale

    R is a collaborative project with many contributors.
    Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications.

    Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help.
    Type 'q()' to quit R.

    Rserv started in daemon mode.
    ec2-user 8385 1 0 14:51 ? 00:00:00 /usr/lib64/R/bin/Rserve --vanilla
    PID: 8385
    Starting Rserve:  [  OK  ]

(and script hangs here...apparently (maybe) waiting...?)
4

0 回答 0