如何使用python调试死锁? [英] How to debug deadlock with python?

查看:170
本文介绍了如何使用python调试死锁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个多线程应用程序,这是一个僵局。



我正在使用Visual C ++ Express 2008来跟踪程序。一旦发生死锁,我只是暂停程序跟踪。我发现,当发生死锁时,我的C ++扩展将有两个叫做python的线程。



所有这些都使用python代码中的Queue,所以我猜猜Queue可能会导致死锁。但是,一旦扩展进入python代码,我看不到来自VC ++调试器的asm代码和二进制文件。



我想知道有没有在暂停程序后,转储python代码调用堆栈的方法?我如何知道线程中有什么锁会导致死锁?

解决方案

如果您可以使用gcc编译扩展模块例如,使用 Cygwin ),您可以使用gdb和 pystack gdb宏在这种情况下获得Python堆栈。我不知道是否可以在Visual C ++ Express中做一些相当于pystack的内容,但是您可能会从pystack宏实现中获得一些想法。



您提到您只能在VC ++调试器中看到asm / binary,您应该确保使用调试符号编译Python。如果VC ++仍然显示asm,那么您可能需要告诉VC ++源文件的位置(不幸的是,几年以前并没有使用VC ++,所以我不能确定你可能需要做什么,如果是这样)



您还可以通过向代码添加大量日志记录来获取一些重要信息,包括Python端和C ++扩展名。



在任何情况下,我几乎肯定死锁不是由于Queue,而是您自己的代码。


I am developing a multi-threading application, which is deadlocking.

I am using Visual C++ Express 2008 to trace the program. Once the deadlock occurs, I just pause the program and trace. I found that when deadlock occurs, there will be two threads called python from my C++ extension.

All of them use Queue in python code, so I guess the deadlock might caused by Queue. But however, once the extension goes into python code, I can't see nothing but asm code and binary from the VC++ debugger.

I would like to know are there any way to dump the call stack of python code after I paused the program? And how can I know what lock are there in threads caused the deadlock?

解决方案

If you can compile your extension module with gcc (for example, by using Cygwin), you could use gdb and the pystack gdb macro to get Python stacks in that situation. I don't know if it would be possible to do something equivalent to pystack in Visual C++ Express, but you might get some ideas from the pystack macro implementation anyway.

Since you mention you only see asm/binary in the VC++ debugger, you should make sure you compile Python with debug symbols. If VC++ is still showing asm, it might be that you need to tell VC++ where the source files are (sorry, haven't used VC++ in years so I can't tell what exactly you might need to do if this was the case).

You might also get some important information by adding lots of logging calls to your code, both Python side and your C++ extension.

In any case, I am almost certain the deadlocks are not due to Queue, but your own code.

这篇关于如何使用python调试死锁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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