1 import datetime
7
10 """
11 A simple timer that will indicate when an expiration time has passed.
12 """
14 "Create a timer that expires at `expiration` (UTC datetime)"
15 self.expiration = expiration
16
17 @classmethod
19 """
20 Return a timer that will expire after `elapsed` passes.
21 """
22 return cls(datetime.datetime.utcnow() + elapsed)
23
25 return datetime.datetime.utcnow() >= self.expiration
26
29 "An exception when a lock could not be acquired before a timeout period"
30
33 """
34 Keep track of the time and detect if a timeout has expired
35 """
36 - def __init__(self, session_id, timeout):
42
44 if self.timer.expired():
45 raise LockTimeout(
46 "Timeout acquiring lock for %(session_id)s" % vars(self))
47 return False
48