1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """WatchdogTimer timeout objects."""
10 class WatchdogTimer(object):
11 """A resetable timeout-based watchdog.
13 This object is threadsafe.
16 def __init__(self
, timeout
):
17 """Initializes the watchdog.
20 timeout: The timeout in seconds. If timeout is None it will never timeout.
22 self
._start
_time
= time
.time()
23 self
._timeout
= timeout
26 """Resets the timeout countdown."""
27 self
._start
_time
= time
.time()
30 """Returns the elapsed time of the watchdog."""
31 return time
.time() - self
._start
_time
33 def GetRemaining(self
):
34 """Returns the remaining time of the watchdog."""
36 return self
._timeout
- self
.GetElapsed()
41 """Whether the watchdog has timed out.
44 True if the watchdog has timed out, False otherwise.
46 remaining
= self
.GetRemaining()
47 return remaining
is not None and remaining
< 0