简体   繁体   中英

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?

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.

You need use RPC to call python function on remote server.

There are many libs around. Let's take RPyC lib for example:

>>> 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.

Please read tutorials to learn how to start RPyC server and deploy your code on remote machine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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