Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pausing the Python console

Tags:

python

console

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.

like image 978
Randomblue Avatar asked Dec 02 '11 16:12

Randomblue


People also ask

How do I pause a Python program?

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

How to pause a program to get input from the user?

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):

How do I get back to the console in Python?

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.

How do I clear the console in Python?

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.


2 Answers

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

like image 181
MagerValp Avatar answered Sep 21 '22 11:09

MagerValp


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

like image 24
jkysam Avatar answered Sep 20 '22 11:09

jkysam