add tag
user202729
Put the following in `a.py`:

```
#!/bin/python3
try:
	while True: pass
except KeyboardInterrupt:
	pass
```

Run with `python a.py`:

```
$ python a.py
```

Press `Ctrl+C` to interrupt it:

```
^CTraceback (most recent call last):
  File "/tmp/a.py", line 3, in <module>
    while True: pass
KeyboardInterrupt
```

Why is the error still printed and not captured?

Python version: Python 3.11.3, on Linux.
Top Answer
daviewales
I'm not able to reproduce your question.

I copied and pasted your code and ran it, and it exits without printing a traceback.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.