Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#35: Improve keyboard interrupt handling in iPython #38

Merged
merged 5 commits into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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