-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Monitoring thread to prevent tqdm taking too much time for display #251
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
Conversation
Current coverage is 91.77% (diff: 100%)@@ master #251 diff @@
==========================================
Files 7 7
Lines 485 523 +38
Methods 0 0
Messages 0 0
Branches 89 92 +3
==========================================
+ Hits 439 480 +41
+ Misses 44 43 -1
+ Partials 2 0 -2
|
All done, good to go for me. Please review me :) |
@@ -15,7 +15,9 @@ | |||
from ._utils import _supports_unicode, _environ_cols_wrapper, _range, _unich, \ | |||
_term_move_up, _unicode, WeakSet | |||
import sys | |||
from time import time | |||
from threading import Thread | |||
from threading import Event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lrq3000 merge into from threading import Thread, event
?
@lrq3000 ding! reviewing done. |
Thank's @CrazyPython, I fixed what you reviewed :) However I would like a more code oriented review about whether we should include this or not. I think it's a good idea obviously because I'm biased (else I wouldn't have spend the time to implement it), but if you guys can think of some edge case to try this feature out (and see whether it can fail or have shortcomings) it would help a lot! Or we can merge and see later :) At least it's 100% unit tested, so it doesn't break anything and it's working like expected on the cases it's supposed to fix. |
@lrq3000 I'll see what I can do... also Travis CI... |
@CrazyPython What about TravisCI? |
@@ -716,12 +797,13 @@ def __iter__(self): | |||
# Note: does not call self.update(1) for speed optimisation. | |||
n += 1 | |||
# check the counter first (avoid calls to time()) | |||
if n - last_print_n >= miniters: | |||
if n - last_print_n >= self.miniters: | |||
miniters = self.miniters # watch monitoring thread changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we directly modify self.miniters
or am I missing something? I'm probably missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an optimization, we store instance variables as local function variables, this speeds up the calculations a great deal because there's no dot reference lookup. But here we need to access self.miniters since it can be modified by the monitoring thread.
@CrazyPython Thank's for editing your comment: lemurheavy/coveralls-public#838 (comment) 👍 |
Nice. Surprised you got a response. I filtered all github emails a few days ago since almost all of them were essentially spam. Pity. |
@casperdcl ignore those and just use the gh notif system |
@casperdcl Actually we could drop coveralls as we are using codecov's branch coverage (whereas coveralls is only statement coverage as far as I know). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Merged in commit f78ecc6. |
Self-reminder: next time use (close #id) instead of just (#id) in the commit message, this will automatically define the PR as closed: http://stackoverflow.com/questions/23015168/how-to-close-a-github-pull-request-with-a-commit-comment Also gitreflow and git-when-merged might become handy in the future. |
@lrq3000 did you mean to close this? I intended you to merge #250 into #251, not the other way around. Currently, comparing https://github.com/tqdm/tqdm/pull/250/commits to https://github.com/tqdm/tqdm/pull/251/commits it looks like you're missing things. |
Sorry but too many messages, I processed them one by one yesterday so I didn't see the order before after I was finished with merging this one. Anyway they are two different PRs, why should they be merged? |
It's normal that the commits history is different, I rebased #250 over #251. I mean, the PR names exactly mean what it's written: #251 was a new feature (the monitoring thread), while #250 was two bugfixes. This is why I didn't merge them, I figured it's easier to review and accept bugfixes rather than new features, so I separated every PRs into two types: bugfixes or new features. And it's better to merge them separately in case there are bugs in the future (they will probably be imputable to the new feature #251 rather than the bugfix #250). |
arg ok did you squash merge this branch into master? |
c052097
to
1cd7cce
Compare
Yes, I thought the review was a signal that I could merge. Also, I did add a few corrections when I merged into master. I will check what is missing since I have a local copy. |
But that's weird, why didn't you want to squash merge? It made more sense to me to squash because it was easier to track down then... |
Ok nevermind, there's just the |
I haven't tagged and formally released master yet so we can squash any minor corrections still. I think minor PR = 1 commit rebase/squash merge. major PR (eg this) = rebase and squash debug commits, then master merge --no-ff. |
Ok I'll do that in the future, thank's for explaining. 2016-10-31 2:58 GMT+01:00 Casper da Costa-Luis notifications@github.com:
|
Added a monitoring thread that will check all tqdm instances regularly and reduce miniters if necessary. This should fix issues like #249 and #54 for good.
About performance impact:
self.miniters
. No problem here, the problem is withtqdm.__iter__()
since it doesn't do any access to self variables inside loops. So I had to modify the loop to accessself.miniters
. My reasoning is that accessingself.miniters
will use less CPU than callingtime.time()
, but I didn't try it out. If someone wants to profile to see the impact ofself.miniters
, that would be great!/EDIT: profiled, here are the results:
Normal tqdm (pre-PR):
Normal tqdm no miniters:
Monitoring thread PR:
Note that for all other tests in
examples/simple_examples.py
, they all show similar performances between standard tqdm and monitoring thread PR (of course theno miniters
is slower).So there is a small performance hit, which is still way better than removing
miniters
completely: removingminiters
doubles the computation time, whereas the monitoring thread has an overhead of 10% (2s here). The perf hit doesn't even come from the monitoring thread itself, but rather from usingself.miniters
instead ofminiters
intqdm.__iter__()
. This seems to slow down by a linear constant, so it's indeed noticeable but it can be ok (or if we can find a way around it would be better but I can't think how). Makes tqdm go from 20s to 22s for the task above.Note that there is no performance impact on manual tqdm. The perf hit is only on iterable tqdm.
TODO:
self.miniters
intqdm.__iter__()
isn't too much of a burden.TMonitor.join()
).TMonitor
to support virtual discrete timer, just store inself._time
andself._sleep
like we do intqdm
).