python中有没有像java中的jstack命令
天蓬老师
天蓬老师 2017-04-17 13:04:00
0
3
1015
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
PHPzhong

There is nothing as convenient and direct to use as jstack. Generally speaking, there are several solutions:

  • IDE: Use tools such as PyCharm, Eclpise with Pydev to debug, pause and check each call stack when you feel it hangs.
  • GDB: The advantage is that you can debug the native extension. The disadvantage is also obvious. You need to add Debug Symbols when compiling Python. This is not available by default. To put it simply, it is powerful but not worth the trouble.
  • pdb: Suitable for lower breakpoints...
  • pudb: Change the code. At the program entry import pudb; pudb.set_interrupt_handler(), you can press Ctrl-C to enter the interactive debugging environment when running. The ease of use is not bad.
  • Use a singal handler to print all stack information. Refer to the install_cry_handler implemented by celery, or look at signalhandler, which comes with Python 3.3.

NOTE: One disadvantage of all solutions that rely on signal is that many POSIX functions will return EINTR when these interrupts are generated, directly causing Python exceptions, such as send, recv, read, write etc. . .

巴扎黑

I don’t know Java, so I don’t know what you want. Do you want to print out the call stacks of all threads? It doesn't seem to be easy.

I am usually:

  1. Try to avoid using threads
  2. Print log. This can roughly infer where the thread is stuck
  3. Strace on each thread to see what system call they are stuck on
PHPzhong

It seems that it is not possible to use multi-threading directly in python because there is something called GIL. As for if you want to see the thread situation, you can use pdb to debug. Try it

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!