A timer class which computes the time elapsed since the start/reset of the timer.
| 111 | |
| 112 | |
| 113 | class Timer(): |
| 114 | """ |
| 115 | A timer class which computes the time elapsed since the start/reset of the timer. |
| 116 | """ |
| 117 | def __init__(self): |
| 118 | self.reset() |
| 119 | |
| 120 | def reset(self): |
| 121 | """ |
| 122 | Reset the timer. |
| 123 | """ |
| 124 | self._start = timer() |
| 125 | self._paused = False |
| 126 | self._total_paused = 0 |
| 127 | |
| 128 | def pause(self): |
| 129 | """ |
| 130 | Pause the timer. |
| 131 | """ |
| 132 | assert self._paused is False |
| 133 | self._paused = timer() |
| 134 | |
| 135 | def is_paused(self): |
| 136 | return self._paused is not False |
| 137 | |
| 138 | def resume(self): |
| 139 | """ |
| 140 | Resume the timer. |
| 141 | """ |
| 142 | assert self._paused is not False |
| 143 | self._total_paused += timer() - self._paused |
| 144 | self._paused = False |
| 145 | |
| 146 | def seconds(self): |
| 147 | """ |
| 148 | Returns: |
| 149 | float: the total number of seconds since the start/reset of the timer, excluding the |
| 150 | time in between when the timer is paused. |
| 151 | """ |
| 152 | if self._paused: |
| 153 | self.resume() |
| 154 | self.pause() |
| 155 | return timer() - self._start - self._total_paused |
no outgoing calls
no test coverage detected
searching dependent graphs…