24

I have the following code which I am running from within Visual Studio Code using Right click > Run Python File in Terminal

import threading


def worker(tid):
    """This is what the thread actually executes"""
    for i in range(tid * 100000):
        print("I'm working on thread {} with count {}".format(tid, i))
    return


def main():
    threads = list()
    for i in range(32):
        t = threading.Thread(target=worker, args=(i,))
        threads.append(t)
        t.start()


if __name__ == "__main__":
    main()

However I want to stop the execution of the script so I have tried with Ctrl+C but the program is still running in the integrated terminal of Visual Studio Code. Is there a way to actually force the stop?

1
  • There is a difference between code running and task running. Commented May 25, 2020 at 14:44

6 Answers 6

32

There should be a trashcan at the top of the integrated terminal window. Clicking the trashcan will kill the window and the processes.

You can also try ctrl-Z or ctrl-D.

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

5 Comments

is there any visual indication that a script is running in VSCode?
Only clicking trashcan helped
the trashcan works however it closes the terminal. It would be nice to be able to stop a script with the terminal still open, so you can see a 'script ended/interrupted' message in the terminal.
neither of these work in version 1.75.0 --- only the trash can
ctrl+c seems to work just like in Powershell or GitBash. Upvoting because it got me to try it.
10

Try: Ctrl+Alt+M, that should do it.

1 Comment

for me didn't work
8

You could Ctrl+Shift+P and then Terminal: Relaunch Active Terminal

Or create a shortcut for it

Comments

6

You may want to install Code Runner in the visual studio extensions. :) I feel that killing the terminal by clicking on the trash bin is a bit tiring for me because I need to open the terminal again.

Comments

6

Right clicking on the integrated terminal window, then clicking 'Kill Terminal' worked for me.

Comments

1

On the python terminal, you need to press both ctrl+c. But, you need to click the terminal before pressing these two keys.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.