vrcmr
vrcmr

Reputation: 161

How to stop infinite while loop python emacs

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?

Upvotes: 4

Views: 3033

Answers (3)

vrcmr
vrcmr

Reputation: 161

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

Upvotes: 4

jmdeldin
jmdeldin

Reputation: 5404

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.

Upvotes: 2

alanmanderson
alanmanderson

Reputation: 8200

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

Upvotes: 0

Related Questions