Skip to content

Commit

Permalink
add last_duration attribute to progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Sep 3, 2015
1 parent 66d8f88 commit f7ddd5e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions dask/diagnostics/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ class ProgressBar(Callback):
... out = some_slow_computation.compute()
[########################################] | 100% Completed | 10.4 s
The duration of the last computation is available as an attribute
>>> pbar = ProgressBar()
>>> with pbar: # doctest: +SKIP
... out = some_computation.compute()
[########################################] | 100% Completed | 10.4 s
>>> pbar.last_duration # doctest: +SKIP
10.4
You can also register a progress bar so that it displays for all
computations:
Expand All @@ -67,6 +76,7 @@ def __init__(self, minimum=0, width=40, dt=0.1):
self._minimum = minimum
self._width = width
self._dt = dt
self.last_duration = 0

def _start(self, dsk):
self._state = None
Expand All @@ -84,6 +94,7 @@ def _finish(self, dsk, state, errored):
self._running = False
self._timer.join()
elapsed = default_timer() - self._start_time
self.last_duration = elapsed
if elapsed < self._minimum:
return
if not errored:
Expand Down
8 changes: 8 additions & 0 deletions dask/diagnostics/tests/test_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,11 @@ def test_with_alias(capsys):
with ProgressBar():
get(dsk, 'f')
check_bar_completed(capsys)


def test_store_time():
p = ProgressBar()
with p:
get({'x': 1}, 'x')

assert isinstance(p.last_duration, float)

0 comments on commit f7ddd5e

Please sign in to comment.