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

查看:22
本文介绍了我怎么知道我的 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

尝试运行您的程序:

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天全站免登陆