简体   繁体   中英

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. 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?

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. 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.

But in regard to this question I guess it has been solved, thanks to AKX for clarifying.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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