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

Jupyter Notebooks don't support Halo #32

Closed
HBadertscher opened this issue Oct 26, 2017 · 12 comments
Closed

Jupyter Notebooks don't support Halo #32

HBadertscher opened this issue Oct 26, 2017 · 12 comments

Comments

@HBadertscher
Copy link

HBadertscher commented Oct 26, 2017

While Halo works perfectly fine in the terminal, I can't get Halo to work inside a Jupyter notebook. I am running the following code in the first cell of the notebook:

from halo import Halo
from time import sleep
with Halo(text='Loading', spinner='dots'):
    sleep(5)

The program runs through without any errors, but no spinner is shown at all.

I figured out, that if you write something to stdout with sys.stdout prior to calling Halo, then the spinner is shown, but each spinner and corresponding text are shown next to each other, i.e. clearing the current line doesn't work.

from halo import Halo
import sys
from time import sleep
sys.stdout.write('test\n')
with Halo(text='Loading', spinner='dots'):
    sleep(5)

returns the output

test
⠋ Loading⠙ Loading⠹ Loading⠸ Loading⠼ Loading⠴ Loading⠦ Loading⠧ Loading⠇ Loading⠏
Loading⠋ Loading⠙ Loading⠹ Loading⠸ Loading⠼ Loading⠴ Loading⠦ Loading⠧ Loading⠇
Loading⠏ Loading⠋ Loading⠙ Loading⠹ Loading⠸ Loading⠼ Loading⠴ Loading⠦ Loading⠧ 
Loading⠇ Loading⠏ Loading⠋ Loading⠙ Loading⠹ Loading⠸ Loading⠼ Loading⠴ Loading⠦ 
Loading⠧ Loading⠇ Loading⠏ Loading⠋ Loading⠙ Loading⠹ Loading⠸ Loading⠼ Loading⠴ 
Loading⠦ Loading⠧ Loading⠇ Loading⠏ Loading⠋ Loading⠙ Loading⠹ Loading⠸ Loading⠼ 
Loading⠴ Loading⠦ Loading⠧ Loading

Is there something wrong on my end, and do you have an idea how to fix that?
It would be really nice if Halo worked with Jupyter too. Thanks for your efforts and for sharing this library!

@manrajgrover
Copy link
Owner

@HBadertscher This is one feature I would love to include. I feel we would need to create a widget for jupyter notebook and ipython so that spinner renders as expected. I don't have experience with that, hence will take me a while to finalize the fix and get this working.

If you would like to work on this, feel free to take this one up and I will assign it to you.

@manrajgrover
Copy link
Owner

Just adding here. If spinner is started in a cell in iPython and not stopped within the same cell, the spinner cannot be stopped. Need to explore this a little more. A widget might fix this.

@winterjung
Copy link
Contributor

@manrajgrover Can I try to implement this feature? I don't have experience with ipython and jupyter widget too, but it's so interesting to work.

refer

@manrajgrover
Copy link
Owner

@jungwinter sure! Please go ahead and give it a try.

@winterjung
Copy link
Contributor

winterjung commented Dec 29, 2017

@manrajgrover I made prototype and can test in notebook.

  • First, from ipywidgets import HTML is tried, but problem was happen about color ansi code.
  • Second, from ipywidgets.widgets import Output, It's work well now. I overwrite __init__, clear, _render_frame_, start, stop_and_persist.

I checked examples work fine, but not yet contain any jupyter test code.

capture-gif

@winterjung
Copy link
Contributor

winterjung commented Dec 29, 2017

And when I run pylint, SyntaxError occurs. Could you help me to handle this error?
When running tox, py27 and py36 tests are passed, but pylint is failed.

(halo-venv) halo git:feature-notebook ❯❯❯ pylint --errors-only --rcfile=/Users/WinterJ/Github/halo/.pylintrc --output-format=colorized halo
Traceback (most recent call last):
  File "/Users/WinterJ/.pyenv/versions/halo-venv/bin/pylint", line 11, in <module>
    sys.exit(run_pylint())
  File "/Users/WinterJ/.pyenv/versions/3.6.1/envs/halo-venv/lib/python3.6/site-packages/pylint/__init__.py", line 13, in run_pylint
    Run(sys.argv[1:])
  File "/Users/WinterJ/.pyenv/versions/3.6.1/envs/halo-venv/lib/python3.6/site-packages/pylint/lint.py", line 1260, in __init__
    'init-hook')))
  File "/Users/WinterJ/.pyenv/versions/3.6.1/envs/halo-venv/lib/python3.6/site-packages/pylint/lint.py", line 1361, in cb_init_hook
    exec(value) # pylint: disable=exec-used
  File "<string>", line 8
    ZGljdChfX2ZpbGVfXz1hY3RpdmF0ZV90aGlzKSkK'.decode('base64')
                                            ^
SyntaxError: invalid syntax

@manrajgrover
Copy link
Owner

@jungwinter This looks amazing! I'll have a look at the code soon. Regarding lint error, I'll have a look at it as well while going through your code. Could you please check if this works on ipython as well?

@winterjung
Copy link
Contributor

@manrajgrover Thanks for reviewing! I checked Halo already works well. Although HaloNotebook doesn't work in ipython shell. I think it's not a problem because there is the original halo. If there are any problems I didn't recognize, please let me know.

@manrajgrover
Copy link
Owner

@jungwinter I remember the issue with iPython. If a user does not handle keyboard interrupt and the spinner is running, a KeyboardInterrupt is thrown but the spinner keeps spinning. I'm creating an issue for this.

@winterjung
Copy link
Contributor

@manrajgrover Oh, I didn't check that issue. I worked a little to solve that problem. Please check my comment. #35 (comment)

@manrajgrover
Copy link
Owner

@jungwinter Please send a PR for this. I'll review the code. 😄 Thank you for working on this!

manrajgrover added a commit that referenced this issue May 6, 2018
Feature #32: Available Halo in jupyter notebook
@manrajgrover
Copy link
Owner

This is fixed in #40 thanks to @jungwinter! This will be made available soon in next release. I need to do few fixes before making a release.

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

No branches or pull requests

3 participants