rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.53k stars 206 forks source link

multiple frozen alive bars produced below active alive bar. #203

Closed AshleyBlum closed 1 year ago

AshleyBlum commented 2 years ago

When using spyder through anaconda multiple frozen alive bars are occasionally produced below the active alive bar for a loop that analyzes the RGB of more then 3,000,000 pixels (takes about 18 secs). Developing components.zip

Thank you very much for your assistance!

rsalmei commented 2 years ago

Please do not send loads of code like this, zipped or not. Use triple backticks here and cite directly the parts affected that you need help with. By "multiple frozen bars" I assume something should have made the shell screen scroll up, and old representations of the bar became lost above it (not below). Is that it?

AshleyBlum commented 2 years ago

Sorry for the incorrect formatting. Yes you are correct, the “living” alive bar occasionally gets pushed above the frame of the shell screen so that it’s no longer visible because so many frozen copies have been produced but it typically only that bad in the full program. In the small portions I provided here it only produces a few frozen copies and it does not do this every time either.

from PIL import Image
#The_image = input('What is the name of the image (make sure to include file type ex: .tiff, .jpeg)? : ')
The_image = "100x trial.tif"
img = Image.open(The_image)
img = img.convert ('RGB')
width, height = img.size
print("Dimensions:", img.size, 'Total number of pixels:', width * height)
print(width)
print(height)
print()
print('scanning image pixels')

the_r = []
the_g = []
the_b = []
def compute():
    #pixel scan
    for right in range(0,width):
        X = right

        for down in range(0,height):
            Y = down
            pixelRGB = img.getpixel((X,Y))
            R,G,B = pixelRGB
            the_r.append(R)
            the_g.append(G)
            the_b.append(B)
            yield
from alive_progress import alive_bar

with alive_bar(width*height) as bar:
    for down in compute():
        bar()
print()

print('R: ', sum(the_r)/len(the_r))
print('G: ', sum(the_g)/len(the_g))
print('B: ', sum(the_b)/len(the_b))
Screenshot 2022-10-31 at 4 48 15 PM
rsalmei commented 2 years ago

Ok, it seems your shell is not reporting the number of columns it has. Please run this:

import os
os.get_terminal_size()
AshleyBlum commented 2 years ago

Thank you for your help. I received this output:

os.terminal_size(columns=80, lines=30)

Additionally here is one of the longer examples of when the live bar got frazzled.

scanning image pixels
|████████████████████████████████████████| 3145728/3145728 [100%] in 24.9s (126158.79/s)                               
|███████▏                                | ▄▆█ 561616/3145728 [18%] in 6s (92025.3/s, eta: 28s) 
|███████▌                                | ▆▄▂ 586775/3145728 [19%] in 7s (88934.6/s, eta: 29s) 
|████████                                | ▇▇▅ 628789/3145728 [20%] in 7s (85122.8/s, eta: 30s) 
|████████▊                               | ▂▄▆ 691048/3145728 [22%] in 8s (85137.0/s, eta: 29s) 
|███████████████▋                        | ▄▆█ 1231123/3145728 [39%] in 12s (105294.4/s, eta: 18s) 
|█████████████████▋                      | ▅▇▇ 1389987/3145728 [44%] in 13s (109477.6/s, eta: 16s) 
|██████████████████▉                     | ▃▁▃ 1488073/3145728 [47%] in 13s (111776.2/s, eta: 15s) 
|████████████████████████████████        | ▂▂▄ 2519443/3145728 [80%] in 20s (127098.0/s, eta: 5s) 
|█████████████████████████████████████▏  | ▇▇▅ 2918886/3145728 [93%] in 22s (130865.2/s, eta: 2s) 
|███████████████████████████████████████▌| █▆▄ 3104307/3145728 [99%] in 25s (126635.4/s, eta: 0s) 
rsalmei commented 1 year ago

Hey @AshleyBlum, are you sure? It doesn't add up... These examples you've sent are all using between 96 and 119 columns of output, and if alive_progress was really getting an os.terminal_size(80, 30), it would truncate all output in 80 columns...... So, are you sure they both are on the exact same terminal session?

rsalmei commented 1 year ago

Closing as stale.