新的信息
This commit is contained in:
1 parent
c66fc76e10
commit
345790cb05
51 files changed
+5187
-61
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import paramiko,time,sys
|
||||
|
||||
def main_optimize_model(pid):
|
||||
try:
|
||||
# 创建SSH对象
|
||||
ssh = paramiko.SSHClient()
|
||||
# 允许连接不在known_hosts文件中的主机
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
print('start connect')
|
||||
# 连接服务器
|
||||
ssh.connect('connect.bjc1.seetacloud.com', username='root', password='QoQA8q3Ds2VB', port=33733)
|
||||
print('connect success')
|
||||
|
||||
# 使用nohup执行命令,并将输出重定向到文件
|
||||
command = f'nohup seg_python /data/code/optimize_model_xj/optimize_model.py -pid {pid} >{pid}.log 2>&1&'
|
||||
stdin, stdout, stderr = ssh.exec_command(command)
|
||||
|
||||
# 打印命令是否启动成功
|
||||
print("Command executed")
|
||||
finally:
|
||||
# 确保连接被关闭
|
||||
if ssh:
|
||||
time.sleep(1)
|
||||
ssh.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
pid = sys.argv[1]
|
||||
main_optimize_model(pid)
|
||||
|
||||
Reference in new issue
Block a user