classification
Title: Occasionally check for Ctrl-C in long-running operations like sum
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: haypo, ncoghlan, rhettinger, steven.daprano, terry.reedy, wim.glenn
Priority: normal Keywords:

Created on 2016-02-12 17:47 by steven.daprano, last changed 2016-03-30 22:11 by wim.glenn.

Messages (5)
msg260189 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2016-02-12 17:47
There are a few operations such as summing or unpacking infinite iterators where the interpreter can become unresponsive and ignore Ctrl-C KeyboardInterrupt. Guido suggests that such places should occasionally check for signals:

https://mail.python.org/pipermail/python-ideas/2016-February/038426.html
msg260238 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2016-02-13 12:41
At least list() and potentially other container constructors are also affected.

While it's mentioned in the thread, I'll explicitly note here that the problem is specifically with iterators implemented in C, like itertools.count().

Iterators implemented in Python already evaluate Python code on each iteration, which means Ctrl-C gets detected and converted to KeyboardInterrupt.
msg260535 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-02-19 23:53
Great idea.  In Windows, closing the window with [x] will kill the process, at the cost of loosing its contents.  In IDLE's Shell, Restart Shell will do the same without killing IDLE, but it is easy to not know of or forget that option in a moment of panic.
msg260536 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2016-02-19 23:59
> Great idea.  In Windows, closing the window with [x] will kill the process, at the cost of loosing its contents.

Note: after a few years, I heard that Windows supports something like SIGKILL: CTRL+Pause kills the current process ;-) You loose the process, but you don't have to close the terminal, confirm and reopen a new terminal, go back to your working directly, etc.

Note 2: Even more off-topic, type .~<enter> in an SSH session to kill it, again it avoids to reopen a terminal window ;-)
msg260556 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-02-20 03:59
I verified that ^Break(pause) works.  It even causes ^C to be printed.
History
Date User Action Args
2016-03-30 22:11:23wim.glennsetnosy: + wim.glenn
2016-02-20 03:59:47terry.reedysetmessages: + msg260556
2016-02-19 23:59:36hayposetmessages: + msg260536
2016-02-19 23:53:19terry.reedysetnosy: + terry.reedy
messages: + msg260535
2016-02-14 04:13:54rhettingersetmessages: - msg260255
2016-02-13 23:25:06rhettingersetmessages: + msg260255
2016-02-13 12:56:57serhiy.storchakasetnosy: + rhettinger
2016-02-13 12:41:11ncoghlansetnosy: + ncoghlan
messages: + msg260238
2016-02-12 17:48:32hayposetnosy: + haypo
2016-02-12 17:47:32steven.dapranocreate