Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See if previous command is still running in PyCharm IPython console?

Is there any way to see if a command is currently being executed in the PyCharm console?

Running an interactive python session in the terminal, after executing a command, the prompt disappears until execution has finished. For example when I call time.sleep(5), it takes 5 seconds until the >>> appears again, so I know the command is still being executed.

Running an IPython console in PyCharm the prompt never disappears. Only when I start typing again I get a message "Previous command is still running". This way it's hard to see when a command has finished without constantly "probing" the prompt.

like image 380
malte Avatar asked Sep 15 '15 16:09

malte


1 Answers

I've found the best way to do when using IPython is to the %time magic command whenever you need to run a long command. For details, see https://ipython.org/ipython-doc/3/interactive/magics.html#magic-time

Usage:

In[1]: %time time.sleep(5)
Wall time: 5 s

The second line will appear when the code finishes. This also has the added bonus of telling you how long execution took.

Note: Don't accidentally confuse it with the %timeit command which will run your code several times

like image 58
Jezzamon Avatar answered Oct 04 '22 07:10

Jezzamon