Net-ssh会话超时 [英] Net-ssh session timeout
问题描述
我正在使用Net-ssh
启动远程Python脚本.当Python脚本执行时间较长(大约20分钟)时,Ruby脚本似乎挂起并且永远无法完成.
I am using Net-ssh
to launch a remote Python script. The Ruby script seems to hang and never complete when the Python script takes a long time to execute (around 20 minutes).
我已经通过直接运行脚本来对其进行了测试,并且脚本完整无误.当在较短的时间内执行脚本时,一切也都可以正常工作.
I have tested the script by running it directly and it completes without any error. Also everything works fine when the script is executed in a shorter amount of time.
这是我正在使用的代码的一部分:
This is an extract of the code I am using:
(0..(@number_of_vms - 1)).each_with_index do |vm, i|
threads << Thread.new do
Net::SSH.start('ip-address-vm', user, options = ...) do |session|
cmd = 'python python_script.py'
output = session.exec!(cmd)
end
end
end
threads.each {|thr| thr.join }
这可能与ssh会话的某种超时有关吗?
Could this be related to some kind of timeout for the ssh session?
我已经验证了脚本在远程服务器上已成功完成.
I have verified that the script is completed successfully on the remote server.
推荐答案
问题与SSH服务器超时有关.我通过更改服务器上的设置解决了该问题.我添加了以下行:
The problem was associated to the SSH server time out. I solved the problem by changing the settings on the server. I have added the following line:
ClientAliveInterval 60
在/etc/ssh/sshd_config
基于此文章应该可以在客户端上进行类似的修改:
Based on this article it should be possible to make a similar modification on the client:
ServerAliveInterval 60
/etc/ssh/ssh_config
这篇关于Net-ssh会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!