Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Copyright (c) 2014, Facebook, Inc. All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. #
"""Basic Timer class that can be used as a context manager."""
"""ContextManager protocol enter to start the timer"""
"""ContextManager protocol exit to stop the timer"""
"""Explicitly start/restart the timer"""
"""Explicitly stop the timer"""
def elapsed(self): """Return the duration that the timer was/is active""" # If the timer is not started, return 0.0
# If the timer has not stopped, return the elapsed time until now
# If the timer has stopped, return the difference in times
return str(timedelta(seconds=self.elapsed))
"""Private-ish time to help with mocking/unittests"""
"""Runs function `f` until it returns True or `timeout` elapses.
Returns if f returns True. Raises if timeout is exceeded."""
(timeout, f)) |