2016-08-09 2 views
3

Как реализовать индикатор выполнения в jupyter-notebook?Как реализовать индикатор выполнения

Я сделал это:

count = 0 
max_count = 100 
bar_width = 40 
while count <= max_count: 
    time.sleep(.1) 
    b = bar_width * count/max_count 
    l = bar_width - b 
    print '\r' + u"\u2588" * b + '-' * l, 
    count += 1 

это здорово, когда у меня есть доступ к петле, в котором, чтобы напечатать материал из. Но кто-нибудь знает что-нибудь умное, чтобы запустить индикатор прогресса какой-то асинхронно?

ответ

5

Вот решение (после this).

from ipywidgets import FloatProgress 
from IPython.display import display 
import time 

max_count = 100 

f = FloatProgress(min=0, max=max_count) # instantiate the bar 
display(f) # display the bar 

count = 0 
while count <= max_count: 
    f.value += 1 # signal to increment the progress bar 
    time.sleep(.1) 
    count += 1 
2

Вы можете попробовать tqdm. Пример кода:

# pip install tqdm 
from tqdm import tqdm_notebook 

# works on any iterable, including cursors. 
# for iterables with len(), no need to specify 'total'. 
for rec in tqdm_notebook(positions_collection.find(), 
         total=positions_collection.count(), 
         desc="Processing records"): 
    # any code processing the elements in the iterable 
    len(rec.keys()) 

Демо: https://youtu.be/T0gmQDgPtzY