alphatwirl / atpbar

Progress bars for threading and multiprocessing tasks on terminal and Jupyter Notebook
https://alphatwirl.github.io/atpbar/
MIT License
93 stars 10 forks source link

NameError: name 'ProgressBarJupyter' in Spyder IDE #15

Closed wbeardall closed 4 years ago

wbeardall commented 4 years ago

Running the example threading script gives the following error in terminal and Python IDE:

NameError: name 'ProgressBarJupyter' is not defined when calling under the following snippet.

Minimal code to reproduce error

import time, random
import threading

from atpbar import atpbar, flush

def task(n, name):
    for i in atpbar(range(n), name=name):
        time.sleep(0.0001)

nthreads = 5
threads = [ ]

for i in range(nthreads):
    name = 'thread {}'.format(i)
    n = random.randint(5, 100000)
    t = threading.Thread(target=task, args=(n, name))
    t.start()
    threads.append(t)

for t in threads:
    t.join()

flush()

Full error traceback

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/media/storage/will/debug/run_with_threading.py", line 8, in task
    for i in atpbar(range(n), name=name):
  File "/home/will/.local/lib/python3.6/site-packages/atpbar/main.py", line 66, in __iter__
    with fetch_reporter() as reporter:
  File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "/home/will/.local/lib/python3.6/site-packages/atpbar/funcs.py", line 132, in fetch_reporter
    _start_pickup_if_necessary()
  File "/home/will/.local/lib/python3.6/site-packages/atpbar/funcs.py", line 182, in _start_pickup_if_necessary
    presentation = create_presentation()
  File "/home/will/.local/lib/python3.6/site-packages/atpbar/presentation/create.py", line 17, in create_presentation
    return ProgressBarJupyter()
NameError: name 'ProgressBarJupyter' is not defined
TaiSakuma commented 4 years ago

Thank you for letting me know about the error.

I have a quick question. Do you get this error on terminal or on Jupyter notebook?

wbeardall commented 4 years ago

Hi, thanks for the response. I got this error running from terminal.

TaiSakuma commented 4 years ago

I see. Thank you. It is odd that the above error occurs on terminal.

Would you mind letting me know the OS, Python version, and the terminal app that you are using?

wbeardall commented 4 years ago

Apologies, I didn't have time to write things up in depth last night.

I'm running Ubuntu 18.04, Python 3.6.9, and I was running the script from the Spyder4 IDE to test some other things I had going on. I'll edit the original post with full details.

TaiSakuma commented 4 years ago

Thank you for the detail. I'll have a look.

TaiSakuma commented 4 years ago

I released version 1.0.7, which addresses the issue.

The same error shouldn't occur in this version. However, the progress bars won't be shown in Spyder IDE. The progress will be printed instead in the manner described in this section of README.

The console in Spyder IDE is not a TTY device. In fact, sys.stdout.isatty() returns False. The same code that draws the progress bars on Terminal doesn't work in Spyder IDE. For example, in Spyder IDE, \b doesn't work as a backspace.

The previous versions were trying to instantiate ProgressBarJupyter in Spyder IDE because Spyder IDE was incorrectly detected as Jupyter Notebook. I revised the detection algorithm so as to tell Jupyter Notebook from Spyder IDE.

It shouldn't be too difficult to draw progress bars in Spyder IDE. However, I haven't been able to figure out how to do it in a quick investigation today. What I need to know is how to delete characters and lines in Spyder IDE.

TaiSakuma commented 4 years ago

I assume that the issue has been resolved. Please let me know if the error persists.