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.
Related
I want to make a program stop running for a certain amount of time to save CPU power. I have a self.after function that I want to run to make the program stop running for a set amount of time. However, it always crashes the program.
self.after(int(self.timeSleep*1000),print("Sleeping."))
The word Sleeping. is printed but the window crashes. I thought that Sleeping. should only be printed after the "sleep" was done. I'm not sure what I'm doing wrong and I couldn't find another question like this. Forgive me if it's a stupid mistake as it's my first time using TKinter.
Thanks in advance.
EDIT:
I am not getting any errors in my terminal. By crash I mean the window stops responding.
Your code has the same effect as below:
execute print("Sleeping.")
execute self.after(int(self.timeSleep*1000), None) which is the same as time.sleep(int(self.timeSleep*1000)).
You need to change it to use lambda:
self.after(int(self.timeSleep*1000), lambda: print("Sleeping."))
I found a solution that doesn't require using self.after. Instead, you can use a thread to run this specific method, allowing you to use while loops and time.sleep without crashing the main GUI program.
I am trying to prevent ^C from showing when a user presses CTRL+C while my script is running.
Why do I want to prevent that?
Because things like this will happen and it does not look nice:
$ python3 myscript.py
^CYour pressed CTRL+C
I know there is a similar question here, but it does not work in Python
I found an easy method!
# Returning the cursor to home and dont create a new line
print("\r", end="")
# Now we are able to print on the line where ^C would be displayed
print("Your pressed CTRL+C")
Because things like this will happen...
Just my two cents: the fact that ^C displays in the terminal is a good thing. It's confirmation that SIGINT was sent to the process, as expected. Don't try to remove it; instead, as others have suggested, start a new line if you really want to. Or just exit without printing anything additional at all, like lots of other command line applications.
I am learning python while using for statement loop is not terminating itself to do so I have to use ctrl+z
as u can see nothing is happening after ......
after using ctrl+z the statement got terminated
i m window user currently working on python 2.7.10
i have already read many post for this problem but find non solution please guide me
The interpreter waits for the rest of the for loop, so just press Enter and the loop will execute.
When working in the python interpreter, a line starting with three dots signals that it is waiting for a block to continue (blocks are created by for, if, while, def, class, and other similar statements).
Even if you put everything on one line (which python only allows if the block is exactly one line) as you have done, the interpreter still waits for you to finish the block.
Anytime that enter a statement and see that, you should first make sure that you have finished what you intended to enter (as you have) and then enter just a blank line (just hit enter) on the next line to signal to the interpreter that the block is done.
This might sound like a really dulled down question but I have honestly searched everywhere for it but is there a way where once the user clicks the "exit" or "stop" button to stop there program right after you click that it will write data to a file somewhere? or would that be impossible since you closesd that program? I honestly don't know, Here's my try at it Its nothing really because I don't entirely know how to do it, but I just say this
if (onExit):
f = open('file.txt', mode='w')
f.write (data)
f.close
my onExit is just a Boolean and yeah I'm just not sure how to do it, I know how dumb that code looks btw I just didn't know how to show to you guys that I have tried looking for it other then if I showed you my history tab
Clicking an 'exit' button typically does not actually close a program immediately. Instead, the code that runs when that button is pushed also takes care of saving data.
If we are talking about a console application, which is 'closed' by ctrl-c (i.e. a KeyboardInterrupt), you can use a try-except block:
try:
raw_input()
except KeyboardInterrupt:
# save here
raise
Python does support atexit handlers, but they are most likely not the right solution to your problem.
If you're using PyDev on Eclipse, the terminate button (red square) sends a kill message to the system, which in turn will kill your program without executing further code.
As the previous answer says, you can use the atexit module, but that only works when your program ends normally.
See also: Is it possible for Eclipse to terminate gently instead of using SIGKILL?
I have some code:
l1 = clutter.Label()
l1.set_position(100,100)
for i in range(0,10):
l1.set_text(str(i))
time.sleep(1)
That is designed to show a count from 1 to 10 seconds on the screen in clutter, but I'm getting a strange error. When I run the script normally the screen runs as it should do, but there is no text displayed until 10 seconds are up. However, When I run with breakpoints in pdb the text shows up just fine.
I'm also getting a strange error at the start of the program:
do_wait: drmWaitVBlank returned -1, IRQs don't seem to be working correctly.
Try adjusting the vlank_mode configuration parameter.
But I don't see why that would affect the code out of break points but not in breakpoints.
Any help would be greatly appreciated.
Not sure if you've already figured out the answer to this but:
The reason you are having this problem is because you are blocking the main thread (where all the drawing occurs) with your time.sleep() calls, preventing the library from redrawing the screen.
E.g. your code is currently doing this:
Clutter redraws the screen.
You loop over ten seconds and change the text ten times.
Clutter redraws the screen.
If you want to queue something on a timer, you should look into gobject.timeout_add.
Have you tried posting (or searching) on the Clutter mailing list? Here's someone who got the same message about drmWaitVBlank for example.
My guess is most people on SO wouldn't be familiar with solving Clutter problems. I know I'm not :)