Python paramiko 日志记录弄乱了 stfp 连接 [英] Python paramiko logging messes up stfp connection

查看:53
本文介绍了Python paramiko 日志记录弄乱了 stfp 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 paramiko 打开 sftp 连接以访问远程文件.我在内置函数中的所有代码似乎只有在我没有为 paramiko 启用日志记录时才起作用:

I am using paramiko to open a sftp connection to access a remote file. All my code below in a built in function seems to work only if I don't have the logging enabled for paramiko:

      paramiko.util.log_to_file( 'paramiko.log' )

因此,当我的文件中没有上述代码行时,以下代码有效:

So when I do NOT have the above line of code in my file the code below works:

        client = paramiko.SSHClient()
        client.load_system_host_keys()
        client.set_missing_host_key_policy( paramiko.AutoAddPolicy() )
        client.connect( hostname,user, password)
        sftp = client.open_sftp()
        file = sftp.open( fpath, mode='r', bufsize=1 )

否则 python 将挂在这一行 client.connect( hostname,user, password) 并疯狂地写入 stderr 日志,最终杀死运行我的代码的 VM.

Otherwise python will hang on this line client.connect( hostname,user, password) and writes to the stderr log like crazy eventually killing the VM my code is running on.

特别是paramiko挂在这条线上:

Specifically paramiko hangs on this line:

t.start_client()

在 client.connect 方法中.paramiko 日志中没有任何有用的信息,并且 stderr 充满了没有描述或回溯的错误.

within the client.connect method. Nothing useful comes out in the paramiko log and stderr is filled with errors with no description or tracebacks.

在研究这个问题时我遇到了有一个可用的导入锁,所以当子线程尝试另一个导入时它可以无限期地阻止它"我如何确保打开 sftp 连接的代码永远不会被阻止?

Researching this problem I came across "There is a single import lock available so when a child thread attempts another import it can block it indefinitely" how do I make sure the code opening a sftp connection is never blocked?

推荐答案

这有点远,但我遇到了 logging 使用线程导致死锁的问题.我无法跟踪确切的问题(尽管我怀疑使用 subprocess 可能会加剧它;但我确实通过禁用 logging 模块的线程来解决它支持.

This is a bit of a long shot, but I have had issues with logging's use of threads causing deadlock. I was not able to track the exact problem down (though I suspect it may have been exacerbated by the use of subprocess; but I did solve it by disabling the logging module's thread support.

在激活日志记录之前试试这个:

Try this before you activate logging:

import logging
logging.thread = None

我很想知道这是否能解决您的问题.

I'd be interested to know if this solves your problem or not.

这篇关于Python paramiko 日志记录弄乱了 stfp 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆