Repository: qpid-proton Updated Branches: refs/heads/master c96f10736 -> 553023b95
NO-JIRA: Removed python "with" keyword from utils.py, not supported in jython. Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/553023b9 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/553023b9 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/553023b9 Branch: refs/heads/master Commit: 553023b95aa6a0e651f5d1e34e1e620b1907540c Parents: c96f107 Author: Alan Conway <[email protected]> Authored: Tue Jan 27 09:33:59 2015 -0500 Committer: Alan Conway <[email protected]> Committed: Tue Jan 27 09:51:53 2015 -0500 ---------------------------------------------------------------------- proton-c/bindings/python/proton/utils.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/553023b9/proton-c/bindings/python/proton/utils.py ---------------------------------------------------------------------- diff --git a/proton-c/bindings/python/proton/utils.py b/proton-c/bindings/python/proton/utils.py index 187fc29..65121ee 100644 --- a/proton-c/bindings/python/proton/utils.py +++ b/proton-c/bindings/python/proton/utils.py @@ -191,22 +191,26 @@ class BlockingConnection(Handler): def on_disconnected(self, event): raise ConnectionException("Connection %s disconnected" % self.url); -def atomic_count(start=0, step=1): - """Thread-safe atomic count iterator""" - lock = threading.Lock() - count = start - while True: - with lock: - count += step; - yield count - +class AtomicCount(object): + def __init__(self, start=0, step=1): + """Thread-safe atomic counter. Start at start, increment by step.""" + self.count, self.step = start, step + self.lock = threading.Lock() + + def next(self): + """Get the next value""" + self.lock.acquire() + self.count += self.step; + result = self.count + self.lock.release() + return result class SyncRequestResponse(IncomingMessageHandler): """ Implementation of the synchronous request-responce (aka RPC) pattern. """ - correlation_id = atomic_count() + correlation_id = AtomicCount() def __init__(self, connection, address=None): """ --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
