diff options
author | Rafael H. Schloming <rhs@apache.org> | 2008-03-07 13:55:00 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2008-03-07 13:55:00 +0000 |
commit | 22912b1f7e82542b66f53be02ea1b8be3402e728 (patch) | |
tree | 56bf0bf58c7726fe5f4dd7e8d0adad0ac69f2e53 /python/qpid/util.py | |
parent | 6c5dae81f69c2b5fa8fbc3dee0ac90a6bdbb76fa (diff) | |
download | qpid-python-22912b1f7e82542b66f53be02ea1b8be3402e728.tar.gz |
added timeouts to hello-010-world; switched to conditions rather than events for handling connection/session state; handle session exceptions
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@634678 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid/util.py')
-rw-r--r-- | python/qpid/util.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/python/qpid/util.py b/python/qpid/util.py index e41dfc75fb..d03a9bd7e9 100644 --- a/python/qpid/util.py +++ b/python/qpid/util.py @@ -17,7 +17,7 @@ # under the License. # -import os, socket +import os, socket, time def connect(host, port): sock = socket.socket() @@ -40,3 +40,28 @@ def listen(host, port, predicate = lambda: True, bound = lambda: None): def mtime(filename): return os.stat(filename).st_mtime + +def wait(condition, predicate, timeout=None): + condition.acquire() + try: + passed = 0 + start = time.time() + while not predicate(): + if timeout is None: + condition.wait() + elif passed < timeout: + condition.wait(timeout - passed) + else: + return False + passed = time.time() - start + return True + finally: + condition.release() + +def notify(condition, action=lambda: None): + condition.acquire() + try: + action() + condition.notifyAll() + finally: + condition.release() |