Description
Extensive searching leads me to believe this probably isn't a bug, but I still can't figure out how to get the expected behavior in Code. In a nutshell, "Ctrl-C" should raise a KeyboardInterupt
in a running python program. When run in a vscode-python terminal with python3 program.py
, it works as expected. When launched via debugger, it does not and the program just keeps executing.
Environment data
- VS Code version: 1.52.0
- Extension version (available under the Extensions sidebar): v2020.11.371526539
- OS and version: macOS 10.15.7
- Python version (& distribution if applicable, e.g. Anaconda): 3.7.9 (from homebrew, I think/hope)
- Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
- Relevant/affected Python packages and their versions: N/A
- Relevant/affected Python-related VS Code extensions and their versions: N/A
- Value of the
python.languageServer
setting: Jedi
[NOTE: If you suspect that your issue is related to the Microsoft Python Language Server (python.languageServer: 'Microsoft'
), please download our new language server Pylance from the VS Code marketplace to see if that fixes your issue]
^ Tried this, no change.
Expected behaviour
When I "Start debugging" with "Python: Current file", "ctrl-c" at terminal, SIGINT is passed to python process and raises a KeyboardException wherever it is currently executing.
Actual behaviour
The above works as expected when a program is run from the terminal with python3 program.py,
but when launched with the debugger as above, SIGINT isn't passed to Python.
Steps to reproduce:
- Open new folder.
- Create file "looptest.py"
- Add code:
import time
number = 0
try:
while True:
number += 1
print(number)
time.sleep(.5)
except KeyboardInterrupt:
print("Finished with ctrl-c")
- Use debugger to "run current file"
- Attempt to "ctrl-c" in terminal. Observe output such as the following (ctrl-c input prints as ^C but is otherwise ignored)
1
2
3
^C4
5
^C6
^C7
^C8
- Stop debugger.
- In terminal, run `python3 looptest.py'
- Attempt "ctrl-c"
- Observe output below. ctrl-c is caught as a
KeyboardException
-> % python3 looptest.py 12
3
4
^CFinished with ctrl-c