简体   繁体   English

远程服务器上的 Python 进程需要通过 ssh 连接到其他服务器并继续运行

[英]Python process on remote server need to ssh to other and continue running

Is it possible to solve that a running Python process which is running on a remote server, ssh to other and then continue running?是否可以解决在远程服务器上运行的正在运行的 Python 进程,SSH 到其他服务器然后继续运行的问题?

run in 192.168.100.1
|
ssh to there 192.168.100.2
|
run continuously on 192.168.100.2 and do other functions from py

I tried with subprocess call but when the script call ssh command and connect to the other, it stops and wait there.我尝试使用子进程调用,但是当脚本调用 ssh 命令并连接到另一个时,它会停止并在那里等待。

You need use RPC to call python function on remote server.您需要使用 RPC 在远程服务器上调用 python 函数。

There are many libs around.周围有很多库。 Let's take RPyC lib for example:让我们以RPyC库为例:

>>> import rpyc
>>> c = rpyc.classic.connect("localhost")
>>> c.execute("print 'hi there'")   # this will print on the host
>>> import sys
>>> c.modules.sys.stdout = sys.stdout
>>> c.execute("print 'hi here'")   # now this will be redirected here
hi here

Please note that you need to install RPyC server on your remote host and deploy your python modules there as well.请注意,您需要在远程主机上安装 RPyC 服务器并在那里部署您的 Python 模块。

Please read tutorials to learn how to start RPyC server and deploy your code on remote machine请阅读 教程以了解如何启动 RPyC 服务器并在远程机器上部署您的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM