简体   繁体   English

调试PyThread_acquire_lock死锁

[英]Debug PyThread_acquire_lock deadlock

I have a multithreaded application running in production environment that hangs at the random time with FUTEX_WAIT_PRIVATE state of all threads and gdb shows that all the threads are trying to make lock calling PyThread_acquire_lock . 我有一个在生产环境中运行的多线程应用程序,随机时间挂起所有线程的FUTEX_WAIT_PRIVATE状态,gdb显示所有线程都试图锁定调用PyThread_acquire_lock It is really massive application with tens of thousands code lines and I can not guess in what line this error is occurred. 这是真正庞大的应用程序与成千上万的代码行,我不知道这个错误发生在哪一行。 Can I debug this issue somehow? 我可以以某种方式调试此问题吗? I can patch threading.Lock calling and log to file all locks are acquired/released in the application and then read this file in the case of error occurred again but I think that there are other python functions calling PyThread_acquire_lock . 我可以修补threading.Lock调用和登录文件在应用程序中获取/释放所有锁,然后在再次发生错误的情况下读取此文件,但我认为还有其他python函数调用PyThread_acquire_lock So how can I debug the issue? 那我该怎么调试这个问题呢? Maybe it is possible to "subscribe" on this C function call from Python and log all these calls? 也许有可能从Python“订阅”这个C函数调用并记录所有这些调用?

You are in one step from the answer: attach with gdb to deadlocked process and use Python gdb extensions to examine lines being in a deadlock. 您距离答案只有一步:使用gdb附加到死锁进程并使用Python gdb扩展来检查处于死锁状态的行。

For gdb --version >= 7: 对于gdb --version > = 7:

sudo apt install python2.7-dbg python3-dbg
sudo gdb /usr/bin/python[3] <pid_of_deadlocked_process>
(gdb) thread apply all py-list
(gdb) thread 2
(gdb) py-up
(gdb) py-print <lock_object>

References: https://docs.python.org/devguide/gdb.html , https://wiki.python.org/moin/DebuggingWithGdb 参考文献: https//docs.python.org/devguide/gdb.html,https//wiki.python.org/moin/DebuggingWithGdb

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM