4

I wrote this code:

x = 0
while x == 0:
      print 'd'

When I type C-c! and C-c C-c the code runs.

Now the question is: How I stop the execution of that code?

vrcmr
  • 141
  • 1
  • 10

3 Answers3

4

Many thanks for our answers. Finaly I got the solution. Here is my step by step how-to.

Credits to Omri Barel, Pavel Repin, jmdeldin

Startpoint is: infinite while loop in pythontests.py file,

  1. C-c ! (open the python shell)(you see two windows "buffers", cursor is in the python shell)
  2. C-x o (switch to other window "buffer") (now is the pythontests.py file highlited)
  3. C-c C-C (execute the code)(the lines begin to move and count :))
  4. C-x o (switch to other window "buffer") (now is the python shell highlited)
  5. C-c C-c (stops running process) (now you see the Trackback message)

In my case I got this message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/python-4684wEr.py", line 3, in <module>
    print 'd'
KeyboardInterrupt

And here is the screencast how it works: http://youtu.be/1MbfCHusF9c

vrcmr
  • 141
  • 1
  • 10
  • 1
    This does not always work. In many cases it just appends C-c C-c to the *Python* buffer repeatedly without stopping the underlying execution. I have yet to determine exactly why this happens or how to stop it from running in such a case. – Darren Ringer Jan 12 '17 at 19:34
2

Switch to the *Python* buffer and type C-q C-c to interrupt the script. C-q (quoted-insert) is used to insert control characters because C-c would be intercepted by Emacs. It works in the shell modes too.

jmdeldin
  • 5,354
  • 1
  • 28
  • 21
0

I think you want C-g which will stop running the current command.

ajon
  • 7,868
  • 11
  • 48
  • 86