Browse code

correctly report elapsed time when runner is cancelled before start

This can happen if the runner is started and cancelled before the
event loop starts.

Joseph Weston authored on 19/02/2018 17:26:30
Showing 1 changed files
... ...
@@ -255,7 +255,14 @@ class AsyncRunner(BaseRunner):
255 255
                           "'adaptive.notebook_extension()'")
256 256
 
257 257
     def elapsed_time(self):
258
-        end_time = self.end_time if self.task.done() else time.time()
258
+        if self.task.done():
259
+            end_time = self.end_time
260
+            if end_time is None:
261
+                # task was cancelled before it began
262
+                assert self.task.cancelled()
263
+                return 0
264
+        else:
265
+            end_time = time.time()
259 266
         return end_time - self.start_time
260 267
 
261 268
     def status(self):