ecolab.interruptible

Contents

ecolab.interruptible#

etils.ecolab.interruptible(inner: Iterable[etils.ecolab.colab_utils._T] | Iterator[etils.ecolab.colab_utils._T]) Iterator[etils.ecolab.colab_utils._T][source]#

Catch KeyboardInterrupts to end the loop without raising an Exception.

While this iterator is running, the first SIGINT (e.g. from interrupting the colab runtime, or pressing Ctrl+C ) will not raise an exception but instead end the loop after the current iteration. A second SIGINT will raise a KeyboardInterrupt Exception as usual.

Examples:

for i in interruptible(range(10)):
  print(i)
  time.sleep(3)
Parameters:

inner – arbitrary iterable or iterator

Yields:

elements from inner