解决 paramiko 上的线程清理问题
我有一个使用 paramiko 的自动化流程,并出现此错误:
Exception in thread Thread-1 (most likely raised during interpreter
shutdown)
....
....
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute
'error'
我知道这是清理/线程中的问题,但我不知道如何修复它。
我有最新版本(1.7.6)并根据 this thread,解决了,直接下载代码还是报错。
该故障发生在winxp/win2003下的Python 2.5/2.6上。
我在 __del__ 析构函数中关闭连接,然后在脚本结束之前关闭它,但这些都不起作用。还有更多吗,使用这个错误发生得更早,所以可能与解释器关闭无关?
I have an automated process using paramiko and have this error:
Exception in thread Thread-1 (most likely raised during interpreter
shutdown)
....
....
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute
'error'
I understand that is a problem in the cleanup/threading, but I don't know how to fix it.
I have the latest version (1.7.6) and according to this thread, it was solved, so I download the code directly but still get the error.
The failure occurs on Python 2.5/2.6 under winxp/win2003.
I close the connection in the __del__
destructor, then close it before the end of the script, none of which works. Is there more, using this the error happened earlier, so maybe is not related to interpreter shutdown??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
__del__
不是解构函数。当您删除对象的姓氏时会调用它,而退出解释器时不一定会发生这种情况。任何管理上下文的东西(例如连接)都是
上下文管理器
例如,有关闭
< /a>:无论如何,发生此异常是因为您有一个守护线程仍在尝试执行其工作,而解释器已经关闭。
我认为你只能通过编写 停止的代码来解决这个问题退出之前所有正在运行的线程。
__del__
is not a deconstructor. It's called when you delete a object's last name, which doesn't nessesarily happen when you exit the interpreter.Anything that manages a context, such as connections, is a
context manager
For example there isclosing
:Anyways, this exception happens because you have a daemonic thread that is still trying to do it's work while the interpreter is already shutting down.
I think you can only fix this by writing code that stops all running threads before exiting.
在正常的程序控制流中关闭连接,而不是在 __del__ 中,正如 @THC4k 所说,它不是解构函数,一般来说,您不应该需要使用 < code>__del__(当然也有例外)。
如果您正在创建自己的线程,并且希望它们在主线程退出时正常退出,则需要 .setDaemon(True) 。
Close your connections in the normal program control flow, not in
__del__
, as @THC4k said, it's not a deconstructor, and in general, you shouldn't need to use__del__
(of course there are exceptions).If you're creating your own threads, you need to .setDaemon(True) if you want them to exit normally when the main thread exits.
我现在,却不是这样。但是找到这个讨论,搜索我的 wxpython 应用程序的问题。
解决它,向主框架添加关闭事件。所以所有线程都会关闭。
我希望这对任何人都没有帮助。
I now, is not the case. But a find this discussion, searching a problem whit my wxpython app.
Solve it to add a close event to the main frame. So all the thread's will be close.
I hope this cant help to anyone.