使用 API 时通过 Python Fabric 断开与主机的连接
该网站说:
关闭连接:Fabric 的 连接缓存永远不会关闭 连接本身——它留下了这个 任何正在使用它的人。晶圆厂工具 为您记账吗:它 迭代所有打开的连接并且 在退出之前关闭它们 (无论任务是否 失败与否。)
图书馆用户需要确保他们 显式关闭所有打开的连接 在他们的程序退出之前,尽管我们 计划使这变得更容易 未来。
我已经到处搜索,但我找不到如何断开或关闭连接。我正在循环访问我的主机并设置 env.host_string。它正在工作,但退出时挂起。关于如何关闭有任何帮助吗?重申一下,我使用的是库,而不是 fabfile。
The website says:
Closing connections: Fabric’s
connection cache never closes
connections itself – it leaves this up
to whatever is using it. The fab tool
does this bookkeeping for you: it
iterates over all open connections and
closes them just before it exits
(regardless of whether the tasks
failed or not.)Library users will need to ensure they
explicitly close all open connections
before their program exits, though we
plan to makes this easier in the
future.
I have searched everywhere, but I can't find out how to disconnect or close the connections. I am looping through my hosts and setting env.host_string. It is working, but hangs when exiting. Any help on how to close? Just to reiterate, I am using the library, not a fabfile.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您不想遍历所有打开的连接,那么您需要的是fabric.network.disconnect_all()。文档字符串读取
If you don't want to have to iterate through all open connections,
fabric.network.disconnect_all()
is what you're looking for. The docstring readsFabric 的 main.py 具有以下内容:
fabric.state.connections 是一个字典,其值为:paramiko.SSHClient
所以我要关闭它们。
The main.py for fabric has this:
fabric.state.connections is a dict with the value being: paramiko.SSHClient
So off I go to close those.
您可以使用以下代码片段(使用 Fabric 1.10.1)按主机名断开与特定连接的连接:
You can disconnect from a specific connection, by host name, using the following code snippet (with fabric 1.10.1):