diff options
| author | Joshua Harlow <harlowja@yahoo-inc.com> | 2014-09-02 12:36:52 -0700 |
|---|---|---|
| committer | Joshua Harlow <harlowja@gmail.com> | 2014-10-18 17:51:52 -0700 |
| commit | 7ca631356efd943bf8e246a6a907653a70a35771 (patch) | |
| tree | b69ac462985ec2a7cc76a1422d0570cef17c86c5 /taskflow/utils/threading_utils.py | |
| parent | 4370fd19a5f86ed85e4b54057dd6a695597d0ddc (diff) | |
| download | taskflow-7ca631356efd943bf8e246a6a907653a70a35771.tar.gz | |
Use and verify event and latch wait() return using timeouts
Instead of blocking up the whole test suite when a latch or
event was not decremented to its desired value (or not set for
an event) we should use a reasonably high value that we use
when waiting for those actions to occur and verify that when those
wait() functions return that we have reached the desired state and
if not either raise an exception or stop further testing.
Fixes bug 1363739
Change-Id: I8b40282ac2db9cabd48b0b65c8a2a49610d77c4f
Diffstat (limited to 'taskflow/utils/threading_utils.py')
| -rw-r--r-- | taskflow/utils/threading_utils.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/taskflow/utils/threading_utils.py b/taskflow/utils/threading_utils.py index 2af1702..b3749bc 100644 --- a/taskflow/utils/threading_utils.py +++ b/taskflow/utils/threading_utils.py @@ -15,11 +15,31 @@ # under the License. import multiprocessing +import sys import threading from six.moves import _thread +if sys.version_info[0:2] == (2, 6): + # This didn't return that was/wasn't set in 2.6, since we actually care + # whether it did or didn't add that feature by taking the code from 2.7 + # that added this functionality... + # + # TODO(harlowja): remove when we can drop 2.6 support. + class Event(threading._Event): + def wait(self, timeout=None): + self.__cond.acquire() + try: + if not self.__flag: + self.__cond.wait(timeout) + return self.__flag + finally: + self.__cond.release() +else: + Event = threading.Event + + def get_ident(): """Return the 'thread identifier' of the current thread.""" return _thread.get_ident() |
