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?

2
  • You can press C-c C-\ to quit, and C-c C-c to break. Commented Sep 7, 2012 at 19:47
  • You can aslo kill Python process in the buffer list or ibuffer. Commented Sep 7, 2012 at 23:41

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.