简体   繁体   English

如何打印最后一行 Python 一直卡在

[英]How to print the last line Python has been stuck on

I have a program running on a raspberry pi zero 2 but at a certain point it just stops, no errors, no program exit, can ctrl+c perfectly fine.我有一个在树莓派零 2 上运行的程序,但在某个点它只是停止,没有错误,没有程序退出,可以 ctrl+c 完全正常。 It just stops doing anything and I'm not sure why.它只是停止做任何事情,我不知道为什么。

There is a lot of complicated code that runs before this and it also calls an external library so I don't want to have to scrub through everything (that's a very deep rabbit hole).在此之前运行了很多复杂的代码,它还调用了一个外部库,所以我不想遍历所有内容(这是一个非常深的兔子洞)。 I just want to know the last line it completed before it got stuck so I can un-stuck it.我只想知道它在卡住之前完成的最后一行,这样我就可以解开它。

Is there any way to print the last line that was executed when it gets stuck?有没有办法打印卡住时执行的最后一行? Maybe I can print the last line that was executed when I press ctrl+C?也许我可以打印按 ctrl+C 时执行的最后一行?

So, quite a simple solution really that I apparently was not aware of.所以,我显然没有意识到一个非常简单的解决方案。 Pressing ctrl+c by default will print the traceback for the last few lines.默认情况下按 ctrl+c 将打印最后几行的回溯。 It did not work for me because I had an exception clause that dealt with any keyboard interrupt.它对我不起作用,因为我有一个处理任何键盘中断的例外条款。 Getting rid of that clause forced my program to crash, now I have a separate issue of finding out what ready, _, _ = select.select([self.fd, self.pipe_abort_read_r], [], [], timeout.time_left()) means.摆脱该子句迫使我的程序崩溃,现在我有一个单独的问题是找出ready, _, _ = select.select([self.fd, self.pipe_abort_read_r], [], [], timeout.time_left())的意思。

But in regard to this question I guess it has been solved, thanks to AKX for clarifying.但是关于这个问题我想它已经解决了,感谢AKX的澄清。

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

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