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

iPython notebook keyboard interrupt breaks cell when using Halo #35

Open
manrajgrover opened this issue Dec 30, 2017 · 4 comments · Fixed by #38
Open

iPython notebook keyboard interrupt breaks cell when using Halo #35

manrajgrover opened this issue Dec 30, 2017 · 4 comments · Fixed by #38

Comments

@manrajgrover
Copy link
Owner

Description

Currently, in an iPython notebook, if a user does not handle keyboard interrupt and the spinner is running, a KeyboardInterrupt is thrown but the spinner keeps spinning.

System settings

  • Operating System: MacOS
  • Terminal in use: iTerm 2
  • Python version: 2.7.10
  • Halo version: 0.0.8

Error

Expected behaviour

In [5]: import time
   ...: import random
   ...:
   ...: spinner.start()
   ...: for i in range(100):
   ...:     spinner.text = '{0}% Downloaded dataset.zip'.format(i)
   ...:     time.sleep(random.random())
   ...: spinner.succeed('Downloaded dataset.zip')
   ...:
⠹ 4% Downloaded dataset.zip^C---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-5-81a625f23371> in <module>()
      5 for i in range(100):
      6     spinner.text = '{0}% Downloaded dataset.zip'.format(i)
----> 7     time.sleep(random.random())
      8 spinner.succeed('Downloaded dataset.zip')
      9

KeyboardInterrupt:

⠼ 4% Downloaded

Steps to recreate

Following snippet should recreate the error.

In [1]: from halo import Halo

In [2]: spinner = Halo(text='Downloading dataset.zip', spinner='dots')

In [3]: import time
   ...: import random
   ...:
   ...: spinner.start()
   ...: for i in range(100):
   ...:     spinner.text = '{0}% Downloaded dataset.zip'.format(i)
   ...:     time.sleep(random.random())
   ...: spinner.succeed('Downloaded dataset.zip')

People to notify

@manrajgrover

@winterjung
Copy link
Contributor

In this case, if you type spinner.stop() (doesn't saw but it is kept handling) and press Enter, the spinner stops. But I think you want a more elegant solution.

To solve this problem, we capture KeyboardInterrupt signal, pass to the thread and stop a task immediately. One of the solutions is to implement specific thread class inherited thread.Thread like this. Second is to using signal module. In this way code is more clear and much better but there are maybe platform-specific issues.

I used the second way to solve the problem. Please review my method.

ipython-gif

@winterjung
Copy link
Contributor

winterjung commented Jan 3, 2018

@manrajgrover Can I send a PR for review?

@manrajgrover
Copy link
Owner Author

@jungwinter I would need a little more time to review the methods. Apologies for the delay.

manrajgrover added a commit that referenced this issue Jan 5, 2018
#35: Improve keyboard interrupt handling in iPython
@manrajgrover manrajgrover reopened this Jan 5, 2018
@manrajgrover
Copy link
Owner Author

manrajgrover commented Jan 11, 2018

With reference to #38, adding test case seems to fail on Appveyor. Need to find the reason behind this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants