diff options
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/utils')
-rw-r--r-- | scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py index 6835ea5f..638684c3 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py @@ -2,6 +2,7 @@ import os import sys import string import random +import time try: import pwd @@ -65,3 +66,20 @@ def list_difference (l1, l2): def is_sub_list (l1, l2): return set(l1) <= set(l2) +# a simple passive timer +class PassiveTimer(object): + + # timeout_sec = None means forever + def __init__ (self, timeout_sec): + if timeout_sec != None: + self.expr_sec = time.time() + timeout_sec + else: + self.expr_sec = None + + def has_expired (self): + # if no timeout was set - return always false + if self.expr_sec == None: + return False + + return (time.time() > self.expr_sec) + |