Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop execution of python script in visual studio code?

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?

like image 654
BRabbit27 Avatar asked May 17 '18 07:05

BRabbit27


People also ask

How do I stop a script code in Visual Studio?

VS Code maintains a debug session while the program is running, and pressing the Stop button terminates the program.

How do you end a Python code?

Ctrl + C on Windows can be used to terminate Python scripts and Ctrl + Z on Unix will suspend (freeze) the execution of Python scripts. If you press CTRL + C while a script is running in the console, the script ends and raises an exception.


2 Answers

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.

like image 53
Natsfan Avatar answered Sep 21 '22 03:09

Natsfan


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

like image 36
Rui Nunes Avatar answered Sep 20 '22 03:09

Rui Nunes