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
Automate nested
with position
#87
Conversation
Current coverage is
|
a0bfb4d
to
5c2ad1f
Compare
grr this seems like an alternative to |
@casperdcl yes I thought the same :S But they are different in that So I'm not sure what to do :/ |
Basically, without a centralised dispatcher, we need to do: pos = 0
t0 = tqdm(..., position=pos); pos += 1;
...
t1 = tqdm(..., position=pos); pos += 1;
...
t2 = tqdm(..., position=pos); pos += 1; would be nice if there was some way to neaten this without a dispatcher. I know |
Ooh maybe something like http://stackoverflow.com/questions/8628123/counting-instances-of-a-class ? When we |
class tqdm(object):
n_instances = 0
@classmethod
def increment_instances(cls):
cls.n_instances += 1
return cls.n_instances
@classmethod
def decrement_instances(cls):
cls.n_instances -= 1
def __init__(self, ...):
self.position = self.increment_instances() - 1 if position is None else position
...
def close(self):
self.decrement_instances()
... |
8ac5405
to
b86755f
Compare
just added more to the TODO list. This branch should replace |
@lrq3000 any idea how to fix Travis::pypy failures? I think you wrote the terminal cursor test logic so you're probably going to be better at debugging this than me. |
💯 This is brilliant @casperdcl, using class variables to automate nested printing is perfect! Yes I'll take a look, I'm just going to finish a few other PRs before :) |
8c6a43f
to
8ac5405
Compare
@casperdcl WARNING I wrongly force pushed this branch, please force push your local branch, I've lost the history of the changes you've done! |
PS: I didn't force push while being in this branch, but while being in relative-timing, so this is weird, but I'll be more careful in the future, I will always precise which remote branch I want to force push. |
If you don't have the local history anymore, we can manually restore the commits by fetching the files here: I tried to restore the history using git, but didn't succeed. |
don't worry, I have a backup of this on my phone (was pushing this otg, debian jessie on arm64 FtW). |
8ac5405
to
8c6a43f
Compare
@casperdcl Thank's for restoring the history, I'll work on it later today :) |
@casperdcl : nope, not necessarily, at least not with PyPy: its garbage collector works differently, so if some instances of tqdm are not closed explicitly, PyPy may not collect them (and thus decrease the instances counter) before the end of the whole script, even if the function where tqdm was instanciated is now finished. You can confirm that by printing the number of tqdm instances, you will see that before my commit and after, the counter decreases (and it fixes the issue). Anyway, I took this bug just as an opportunity to clean up old unit tests (ie, to properly call and close tqdm, mainly using the There was also a very vicious bug with rate formatting at initialization, depending on the platform and the interpreter, it could return either |
Ah and this might be problematic: the number of instances in I really like the idea you had, but maybe we should move it to a subclass? |
Ah ok PyPy having different gc makes sense.
|
PS: BTW I think we should specify in the readme how to override automated nesting (we'll do that when this PR is stable enough). Do you plan to add more features? |
There's a bug currently it seems, there's always a newline return between each bar display when doing:
|
Really? Just in this branch? |
Ok problem solved. It happened with commit So the solution was either to force |
Signed-off-by: Stephen L. <lrq3000@gmail.com>
f58d92b
to
bf394dd
Compare
Yes good spot. I thought a regex version might've been necessary there. I did change things so we don't print things like '\r' unnecessarily. |
Yes but in this case it was because there were additional |
Ok I think we should merge this now. Other PRs will need updating to support this but if we merge all of those first we may never get around to merging this (since all the fixes for them would have to be implemented here)! Agreed? |
Yes agreed, all seems to be working well, so we should merge it in! |
Thank's Casper, don't worry about other PRs needing to be updated, I I would also prefer not to release v4.0.0 on PyPi until other branches are 2016-02-04 21:56 GMT+01:00 Casper da Costa-Luis notifications@github.com:
|
@lrq3000 just a reminder, you haven't answered that SO question yet |
@CrazyPython good spot, thx |
@casperdcl Uh, I found a bug. I'm too lazy to open a new issue, so here it is: Using the Removing makes it goes back to normal. |
@casperdcl and the problem exists no matter what when you run it in an embedded IDE window. Don't know why, I'm using PyCharm. |
hmm from tqdm import tqdm
for i in tqdm(range(10), desc='foo'):
for j in tqdm(range(int(1e7)), desc='bar'):
pass
print '\ndone' gives me: foo: 100%|██████████████████████████████████████| 10/10 [00:17<00:00, 1.72s/it]
bar: 100%|█████████████████████| 10000000/10000000 [00:01<00:00, 6460949.98it/s]
done in a normal console window. There's a known issue with idle which doesn't support multiline things. @lrq3000 correct me if I'm wrong. |
also, feel free to upvote my answer on http://stackoverflow.com/questions/23113494/double-progress-bar-in-python/38489852#38489852 ;) |
@CrazyPython Lol thank you for the reminder! @casperdcl You are right, and if the IDE is using IDLE as a widget to run python scripts (as I expect since it's the easiest way), then yes this would explain why some IDE would output garbage. But here it doesn't seem like it's a missing control character problem, but something else. @CrazyPython Could you tell us what IDE you use and on what OS please? |
@lrq3000 Mac OS X. Run or debug mode. Problem does not appear in terminal window. @casperdcl you should mention you are a dev of Also this code bugs out in the terminal and in the IDE.
|
It does not surprise me that this code does bug out, the desc field is not made to include control characters. If you want to change tqdm display, you should use About Casper, yes he is a highly active maintainer and developper for |
@lrq3000 I mean on his SO description @casperdcl |
@lrq3000 @CrazyPython while I may be the primary maintainer of |
@casperdcl speaking of psuedonyms, I just removed all the personal info from my account... you're the only one here that doesn't have psuedonym :P |
xD my name's Casper and I'm the only one not ghosting |
Should fix #83.
I initially planned to make a new class
multi_tqdm()
to centrally manage multipletqdm
bars, but I've found a way to do the same in a decentralized fashion.The only glitch is when all bars have
leave=True
, they will be overwritten by command prompt (just like the old issue withnested
, but here we can't fix that).Sample code:
Should we keep this or rather try to make a centralized
multi_tqdm()
? (but it will be uglier and a good deal slower).Todo (edited):
conflicts withdeprecatenested
StringIO
!?)