简体   繁体   English

在将Fabric用于以下代码时,如何添加超时?

[英]How do I add timeout while using fabric for below code?

Code is as below. 代码如下。 I will explain here. 我会在这里解释。

I use fabric to check the mount point status for 2 server. 我使用交换矩阵检查2个服务器的安装点状态。 The command is 该命令是

df -h /mnt

The problem of this command is that it may hang there forever, so the fabric code will hang forever. 此命令的问题是它可能永远挂在那里,因此结构代码将永远挂起。 I think some timeout mechanism will fix this issue. 我认为某些超时机制可以解决此问题。 But I did not find it on the fabric doc. 但是我没有在结构文档中找到它。 Is there any setting about this ? 有什么设置吗?

import fabric
from fabric import ThreadingGroup as Group

directory = '/mnt'
group = Group('server1', 'server2', user='someuser', connect_kwargs={'password':'somepassword'})
try:
    result = group.run("df -h %s" % directory)
except fabric.exceptions.GroupException as e:
    err = e
    pass

Option #1: use bash timeout to stop the command timeout 10 df -h 选项#1:使用bash超时来停止命令timeout 10 df -h

Option #2: use the run function's timeout parameter . 选项2:使用run功能的timeout参数 timeout is specified in seconds, and a CommandTimeout exception is raised if the command times out. 以秒为单位指定超时,如果命令超时,则会引发CommandTimeout异常。

Group.run

Executes Connection.run on all member Connections. 执行Connection.run所有成员的连接。

and Connection.run Connection.run

wraps an SSH-capable implementation of invoke.runners.Runner.run ; 包装支持SSH的invoke.runners.Runner.run实现; see its documentation for details. 有关详细信息,请参见其文档。

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

相关问题 将chromedriver与Selenium结合使用时,如何更正超时错误? - While using the chromedriver with Selenium, how do I correct a timeout error? 如何使用字典理解编写以下代码 - How do I write below code using dictionary comprehension 我怎么知道下面的代码是否正确? - How do I know if the code below is correct? 如何在下面的代码中实现 DFS? - How do I implement DFS in the code below? 在python中使用.writelines时,如何使代码在文档的新行上添加新输入? - How do I make my code add new inputs on a new line in a document while using the .writelines in python? 在以下情况下使用scrapy时如何处理sub和sup? - How do I handle sub and sup while using scrapy in the scenario below? 如何使用以下代码构建cramer-v矩阵? - How do i build a cramer-v matrix using the below code? 如何使用下面有错误的代码绘制两个正方形? - How do I draw two squares using the code below that has errors? 我想将 R 代码转换为 python。 如何使用python执行以下给定的操作? - I want to convert the R code to python. How to do the below given operation using python? 如何为下面给出的代码片段添加“格式”? - How can I add “format” for the piece of the code which is given below?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM