Closed typecasto closed 3 years ago
Hey, this seems like the default value of Python's util, when it can't retrieve the number of cols. Please enter python or ipython and do:
import shutil
shutil.get_terminal_size()
What is the result?
I can't simulate that, even inside vscode's terminal:
The same thing with your exact code. I'll try to test it on my windows machine, but I don't think it will make any difference.
Could you please paste the code directly on terminal, like I did above? Also, please paste this and let me see the result:
print(''.join(str(x % 10) * 10 for x in range(20)))
https://gfycat.com/AgreeableThoroughAsiaticlesserfreshwaterclam I didn't add any print statements in there, no clue why it did that.
I removed the time.sleep() call, and after it got to the end it looked like this:
(sorry for being slow to respond, I'm turning on email notifications for github so I should respond faster now)
No problem!
Well, that print did print ok, so there isn't anything blocking that. Since I've tested inside vscode myself, that is also not the problem. So, I'm kinda out of clues. Would it be vscode + windows? I haven't had the chance to test in a windows machine yet. To debug more, I'd need to modify the internal code...
Do you have the WSL? Windows Subsystem for Linux? It's really recommended, and surely will work there (besides improving your work joy). Would you be willing to test that?
I've tried to get vscode working on wsl, but whatever I do, running code
always launches the non-wsl vscode. Haven't had time to mess with it much, being this close to christmas. I'll give it a shot again once I get home.
this also happened to me while using cmd and powershell in windows terminal to run python script:
from alive_progress import alive_bar
from tqdm import tqdm # another progress bar package
import time
length = [5000, 6000, 4000, 0]
for l in length:
with alive_bar(l, title="Sending messages...") as bar:
for i in range(length[0]):
time.sleep(0.0001)
bar()
pbar = tqdm(total=length[0])
for i in range(length[0]):
time.sleep(0.0001)
pbar.update()
is this a windows-specific problem?
It does seem to be. I'll try to recreate it on a minimal vm, and either find a way to send it to you or lay out the steps tonight when I get back to the hotel.
It's very strange, I really can't understand why.
I detect the terminal size via shutil.get_terminal_size()
, and I know it returns 80 if it can't find it...
That's all I can think atm.
Thanks @thecakeisalie25, it would be awesome! Maybe create a docker image which does reproduce the problem, and post it in a free repo on hub.docker.com... Humm no, I think now only private repos are free... Maybe its Dockerfile and I can try to build it here.
I don't know any docker, I was just gonna make a vmware/virtualbox appliance and send it over via firefox send or magic-wormhole, and you could experiment with it that way.
Ok, I can try here, no problem. Let me know if you can simulate it!
Issue is replicated in a minimal windows vm running python 3.9.1, it happens in cmd, powershell, and the vscode terminal. I'm uploading the OVA now, if you're using virtualbox you'll have to change the os to a 64 bit one.
https://mega.nz/file/1rwXyCLJ#RueKLGr7A80Q8eM5xXc-Hw0CJ2gCrPpsySnYANqaseU @rsalmei here's the link to the ova, import it and check the bar_test file on the desktop.
That's great, thank you @thecakeisalie25 ! Wow, 17GB, that's gonna take a while. But I'll see to it asap.
if you're using virtualbox you'll have to change the os to a 64 bit one.
What do you mean? I'm not using any, I'll install virtualbox which is free.
Looking through the code, it seems like you wanted to use shutil.get_terminal_size(), but haven't implemented it yet (as per this comment) Loading the core/utils.py file and calling terminal_columns() returns 80:
and if you still want to test on that virtual machine, you have to edit the machine settings, and in that window there's a setting for virtual OS that you need to change to windows 10 64 bit, it defaults to other/unknown which is 32 bit.
Oops, you're right, thank you!
It's been so much time I didn't tinker with alive-progress 1.6 I had forgotten that... Python 2 does not have shutil.get_terminal_size()
!!! I've included it just on alive-progress 2.0, the new next major.
That explains it. That code for Python 2 uses internals of the console terminal, and really does not work on windows, only unix variants like linux and macOS...
As soon as I drop Py2 support it will work as intended..... Thank you @thecakeisalie25, you nailed it. If you know of any way of getting terminal size on Py2 let me know!
Hey, I just realized I can use that code as a fallback, I'm gonna fix it. If it's a Python 3 environment, I'll call the correct method, if not then that fallback is the next best thing... 👍
Hey @thecakeisalie25, great news!! I just fixed it in #70!! Please update and let me know if it is ok...
confirmed fixed, nice work!
Great!! Thank you man! Enjoy, and stay tuned for 2.0! 🎉
are multiple simultaneous progress bars a planned feature for 2.0? That (and color) are the main features I've been wanting for a while now. I love this library btw, recently used it in my first ever actual major python project, which I'm really proud of.
Thanks man! And congrats for your first major project! 🎉
Not yet, 2.0 is dedicated mostly to the spinner Compiler (zero overhead animations!), Python 3 and emoji support (grapheme clusters). You can see more details here: #51
About multiple simultaneous bars, it is an old request, I'd love to implement that but I'm not so sure how... I didn't figure out yet how to render multiple bars at the same time, with possibly very different update speeds, while still making the print hook work... There's more info here: https://github.com/rsalmei/alive-progress/issues/20#issuecomment-605832026
My workaround for this issue is to remind users of my script to keep their terminal window wide.
# To fix the problem of cut-off progress bar messages..
if os.get_terminal_size().columns < 100:
raise AssertionError(
"Your alive progress bars are going to potentially get cut off "
"because your terminal window has fewer than 100 character columns. "
"Please shrink the size of your view or expand the width and try again."
)
Hi @MichaelCurrie,
Yeah, or you could simply shrink the bar from the default 40 chars to as low as 3 chars to not break your script. Just use length=X
.
The issue here was for an actual problem, where the bar was being truncated regardless of the terminal size.
Unfortunately I've just seen that my workaround doesn't fix my problem. No matter how wide the terminal it gets cut off at exactly 80 characters:
But if I override max_cols
option to be something other than the default value of 80, it's fixed:
alive_progress.alive_bar(total_items, max_cols=os.get_terminal_size().columns)
I'm not sure if this is really a bug, more of a caveat emptor to set the max_cols.
@rsalmei that's another good option as you say, to just shrink the bar itself using length=X
.
It cuts off stuff like the ETA and percentage when the numbers are large enough,
This is the vscode terminal if that makes any difference, but it also happens on fluent terminal. Is there a way to make it adapt to my terminal width?
code example: