1

I was learning itertools in Python and accidentally invoked an infinite loop in iPython shell, here's what my inputs:

import itertools as it
list(it.zip_longest(it.count(), [1,2]))

The last line would run indefinitely until the computer crashes.

I tried to terminate the execution with Ctrl-C, but it didn't work.

How do I force the execution to terminate in this case?

Roshin Raphel
  • 2,612
  • 4
  • 22
  • 40
Teddy C
  • 786
  • 10
  • 13
  • 1
    Simply find the process id for the shell, and kill it, or close the terminal. There could be several ways for this. – acpmasquerade Sep 19 '20 at 07:04
  • @acpmasquerade at some point after running the code, the GUI became irresponsive and I had to force quit the app where iPython was run (a terminal emulator / editor / IDE). – Teddy C Sep 19 '20 at 08:19

1 Answers1

2

Python is a interpreted language hence it checks for instruction after each line. The same happens with Ctrl-C too.

Ctrl-C sends KeyboardInterrupt to Python interpreter and it is checked after each Python instruction but the output generation by it.zip_longest(it.count(), [1,2]) is handled in C Code and the interrupt is handled afterwards but interpreter never checks for next instruction hence even on Ctrl-C the execution doesn't stop.

CK__
  • 1,252
  • 1
  • 11
  • 25