我怎么知道我的python脚本挂在哪里? [英] How can I tell where my python script is hanging?

查看:190
本文介绍了我怎么知道我的python脚本挂在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在调试我的python程序,并且遇到了一个使程序挂起的错误,就像在无限循环中一样。现在,我之前遇到了无限循环的问题,但是当它死机时,我可以杀死该程序,并且python吐出一个有用的异常,该异常告诉我在我向它发送kill命令时程序在何处终止。但是,现在,当程序挂起并按ctrl-c时,它不会终止,而是继续运行。有什么我可以用来定位挂断的工具吗?我是剖析的新手,但据我所知,探查器只能为您提供有关已成功完成程序的信息。还是可以使用探查器来调试此类挂断?

So I'm debugging my python program and have encountered a bug that makes the program hang, as if in an infinite loop. Now, I had a problem with an infinite loop before, but when it hung up I could kill the program and python spat out a helpful exception that told me where the program terminated when I sent it the kill command. Now, however, when the program hangs up and I ctrl-c it, it does not abort but continues running. Is there any tool I can use to locate the hang up? I'm new to profiling but from what I know a profiler can only provide you with information about a program that has successfully completed. Or can you use a profiler to debug such hang ups?

推荐答案

让我们假设您正在以以下方式运行程序:

Let's assume that you are running your program as:

python YOURSCRIPT.py

尝试以以下方式运行程序:

Try running your program as:

python -m trace --trace YOURSCRIPT.py

在屏幕上打印大量内容时要有耐心。如果您有无限循环,它将永远持续下去(停止问题)。如果它卡在某个地方,那么大多数情况下,您将卡在I / O上,否则将陷入僵局。

And have some patience while lots of stuff is printed on the screen. If you have an infinite loop, it will go on for-ever (halting problem). If it gets stuck somewhere, then mostly you are stuck on I/O or it is a deadlock.

这篇关于我怎么知道我的python脚本挂在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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