Skip to content

Commit

Permalink
Merge pull request #38 from JungWinter/fix-ipython
Browse files Browse the repository at this point in the history
#35: Improve keyboard interrupt handling in iPython
  • Loading branch information
manrajgrover authored Jan 5, 2018
2 parents 0b667ac + 6a8ed79 commit 8e84336
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions halo/halo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import unicode_literals, absolute_import, print_function

import sys
import signal
import threading
import time
import functools
Expand Down Expand Up @@ -64,6 +65,13 @@ def __init__(self, text='', color='cyan', spinner=None, animation=None, interval
self._spinner_id = None
self._enabled = enabled # Need to check for stream

def handle_keyboard_interrupt(signal, frame):
"""Handle KeyboardInterrupt without try-except statement"""
self.fail(self.text)
raise KeyboardInterrupt

signal.signal(signal.SIGINT, handle_keyboard_interrupt)

def __enter__(self):
"""Starts the spinner on a separate thread. For use in context managers.
Returns
Expand Down
1 change: 1 addition & 0 deletions tests/test_halo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest
import time
import sys
import signal
import io
import logging
import os
Expand Down

0 comments on commit 8e84336

Please sign in to comment.