How to manually terminate a task in Visual Studio Code?

There's currently no key shortcut to terminate a running task. You can, however create your own shortcut for it. Go to File->Preferences->Keyboard Shortcuts and add your shortcut to the keybindings.json.

Here's example code:

{
    "key": "ctrl+shift+alt+t",
    "command": "workbench.action.tasks.terminate"
}

To add a solution in windows:

Extension: Code Runner

Command: Stop code run

Keybinding: Ctrl Alt M

Editor Version: 1.23.1

It could be similar in MacOS, perhaps you need to replace Ctrl to the Command Key.