Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
MoinMoin.util.lock.Timer Class Reference

List of all members.

Public Member Functions

def __init__
def setTimeout
def start
def haveTime
def sleep
def elapsed

Public Attributes

 timeout

Static Public Attributes

float defaultSleep = 0.25
float maxSleep = 0.25

Private Attributes

 _start
 _stop
 _sleep

Detailed Description

Simple count down timer

Useful for code that needs to complete a task within some timeout.

Definition at line 17 of file lock.py.


Constructor & Destructor Documentation

def MoinMoin.util.lock.Timer.__init__ (   self,
  timeout 
)

Definition at line 25 of file lock.py.

00025 
00026     def __init__(self, timeout):
00027         self.setTimeout(timeout)
00028         self._start = None
00029         self._stop = None

Here is the call graph for this function:


Member Function Documentation

Definition at line 60 of file lock.py.

00060 
00061     def elapsed(self):
00062         return time.time() - self._start
00063 

Check if timeout has not passed 

Definition at line 45 of file lock.py.

00045 
00046     def haveTime(self):
00047         """ Check if timeout has not passed """
00048         if self.timeout is None:
00049             return True
00050         return time.time() <= self._stop

def MoinMoin.util.lock.Timer.setTimeout (   self,
  timeout 
)

Definition at line 30 of file lock.py.

00030 
00031     def setTimeout(self, timeout):
00032         self.timeout = timeout
00033         if timeout is None:
00034             self._sleep = self.defaultSleep
00035         else:
00036             self._sleep = min(timeout / 10.0, self.maxSleep)

Here is the caller graph for this function:

Sleep without sleeping over timeout 

Definition at line 51 of file lock.py.

00051 
00052     def sleep(self):
00053         """ Sleep without sleeping over timeout """
00054         if self._stop is not None:
00055             timeLeft = max(self._stop - time.time(), 0)
00056             sleep = min(self._sleep, timeLeft)
00057         else:
00058             sleep = self._sleep
00059         time.sleep(sleep)

Start the countdown 

Definition at line 37 of file lock.py.

00037 
00038     def start(self):
00039         """ Start the countdown """
00040         if self.timeout is None:
00041             return
00042         now = time.time()
00043         self._start = now
00044         self._stop = now + self.timeout


Member Data Documentation

Definition at line 33 of file lock.py.

Definition at line 27 of file lock.py.

Definition at line 28 of file lock.py.

Definition at line 22 of file lock.py.

float MoinMoin.util.lock.Timer.maxSleep = 0.25 [static]

Definition at line 23 of file lock.py.

Definition at line 31 of file lock.py.


The documentation for this class was generated from the following file: