From 3aba9d4777fb96daa317ac1c17177d22cff4353c Mon Sep 17 00:00:00 2001 From: Bas Nijholt <basnijholt@gmail.com> Date: Thu, 25 Oct 2018 11:36:14 +0200 Subject: [PATCH] add the use of 'runner.traceback' and 'runner.elapsed_time()' to the docs --- adaptive/runner.py | 4 ++++ .../tutorial/tutorial.advanced-topics.rst | 21 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/adaptive/runner.py b/adaptive/runner.py index b6d0de49..f3b84b34 100644 --- a/adaptive/runner.py +++ b/adaptive/runner.py @@ -338,6 +338,8 @@ class BlockingRunner(BaseRunner): self._cleanup() def elapsed_time(self): + """Return the total time elapsed since the runner + was started.""" if self.end_time is None: # This shouldn't happen if the BlockingRunner # correctly finished. @@ -532,6 +534,8 @@ class AsyncRunner(BaseRunner): self._cleanup() def elapsed_time(self): + """Return the total time elapsed since the runner + was started.""" if self.task.done(): end_time = self.end_time if end_time is None: diff --git a/docs/source/tutorial/tutorial.advanced-topics.rst b/docs/source/tutorial/tutorial.advanced-topics.rst index d6eabd27..aead0dd4 100644 --- a/docs/source/tutorial/tutorial.advanced-topics.rst +++ b/docs/source/tutorial/tutorial.advanced-topics.rst @@ -298,6 +298,15 @@ raise the exception with the stack trace: runner.task.result() + +You can also check ``runner.tracebacks`` which is a mapping from +point → traceback. + +.. jupyter-execute:: + + for point, tb in runner.tracebacks.items(): + print(f'point: {point}:\n {tb}') + Logging runners ~~~~~~~~~~~~~~~ @@ -337,10 +346,16 @@ set of operations on another runner: learner.plot().Scatter.I.opts(style=dict(size=6)) * reconstructed_learner.plot() -Timing functions -~~~~~~~~~~~~~~~~ +Adding coroutines +----------------- + +In the following example we'll add a `~asyncio.Task` that times the runner. +This is *only* for demonstration purposes because one can simply +check ``runner.elapsed_time()`` or use the ``runner.live_info()`` +widget to see the time since the runner has started. -To time the runner you **cannot** simply use +So let's get on with the example. To time the runner +you **cannot** simply use .. code:: python -- GitLab