I am running some Python code in the console, inside a very long for
loop. I would like to pause the execution of the script, and then be able to resume where I left. Is it possible to pause the Python console?
Note: I don't want to use time.sleep
; I want to be able to externally pause the console in the middle of a loop.
If you're running python in a standard unix console, the usual ctrl-s (pause output, continue with ctrl-q) and ctrl-z (suspend, continue with fg) commands work. If you're running in a windows command shell, use the Pause button (press any key to continue).
If we want to pause a program to get some input from the user, we can do so using the input () or raw_input () function depending upon the Python version. Example code (Python 3): name = input("Please enter your name: ") print("Name:", name) Example code (Python 2):
If you're running in a windows command shell, use the Pause button (press any key to continue). If you are using Unix you can always Ctrl+Z, to go back to the command prompt and then 'fg' to get back to the python console.
A way to make this function more concise is to use a ternary operator and declare a lambda function. Both solutions will clear the console instance that runs the Python code. This is a more brute force approach to clear the console, but it’s just as effective.
If you're running python in a standard unix console, the usual ctrl-s (pause output, continue with ctrl-q) and ctrl-z (suspend, continue with fg) commands work. If you're running in a windows command shell, use the Pause button (press any key to continue).
If you are using Unix you can always Ctrl+Z, to go back to the command prompt and then 'fg' to get back to the python console. On Windows use the Pause button
On Unix you can also do:
To stop: kill -SIGSTOP pid
To continue: kill -SIGCONT pid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With