You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2015/01/27 15:55:59 UTC

qpid-proton git commit: NO-JIRA: Removed python "with" keyword from utils.py, not supported in jython.

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 <ac...@redhat.com>
Authored: Tue Jan 27 09:33:59 2015 -0500
Committer: Alan Conway <ac...@redhat.com>
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: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Re: qpid-proton git commit: NO-JIRA: Removed python "with" keyword from utils.py, not supported in jython.

Posted by Gordon Sim <gs...@redhat.com>.
On 01/27/2015 02:55 PM, aconway@apache.org wrote:
> Repository: qpid-proton
> Updated Branches:
>    refs/heads/master c96f10736 -> 553023b95
>
>
> NO-JIRA: Removed python "with" keyword from utils.py, not supported in jython.

In jython 2.5 I believe you have to use:

   from __future__ import with_statement

(Since jython is used only for testing, perhaps we could even upgrade?)

[...]
> 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

Why do you need an AtomicCount? The intent to allow concurrent requests 
I assume?

The underlying BlockingConnection and engine objects are not threadsafe, 
so if that assumption is correct you will need to prevent threads from 
concurrently accessing the same objects.

>
>   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: commits-unsubscribe@qpid.apache.org
> For additional commands, e-mail: commits-help@qpid.apache.org
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org