You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2020/01/20 17:36:24 UTC
[qpid-proton] branch master updated (1b15be0 -> 9c7b3fc)
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git.
from 1b15be0 PROTON-2005: fix pn_delivery_abort() for multiframe and session outgoing bytes
new 900347e PROTON-2156: [Python] Simplify selectable protocol - Selectable now encapsulates all the events it sends it uses the reactor to send events - Simplified delegate logic
new 826b6ef PROTON-2156: [python] Rework connector scheme to work with tornado ioloop - This also required a small change to the tornado interface code - Add back the helloworld_tornado and helloworld_direct_tornado tests
new 9c7b3fc PROTON-2156: [Python] Fix client_http for changes in tornado
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
python/examples/client_http.py | 25 +++++++++++++------------
python/examples/proton_tornado.py | 9 ++++++---
python/examples/test_examples.py | 6 ++++++
python/proton/_events.py | 1 -
python/proton/_handlers.py | 36 +++++++++++++++++++-----------------
python/proton/_reactor.py | 19 ++++++-------------
python/proton/_selectable.py | 29 +++++++++++++++++------------
7 files changed, 67 insertions(+), 58 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[qpid-proton] 02/03: PROTON-2156: [python] Rework connector scheme
to work with tornado ioloop - This also required a small change to the
tornado interface code - Add back the helloworld_tornado and
helloworld_direct_tornado tests
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit 826b6eff203dee34bc45082e9d05baa805327473
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Fri May 10 12:58:07 2019 -0400
PROTON-2156: [python] Rework connector scheme to work with tornado ioloop
- This also required a small change to the tornado interface code
- Add back the helloworld_tornado and helloworld_direct_tornado tests
---
python/examples/proton_tornado.py | 7 +++++--
python/examples/test_examples.py | 6 ++++++
python/proton/_handlers.py | 26 +++++++++++++++-----------
3 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/python/examples/proton_tornado.py b/python/examples/proton_tornado.py
index 8829a4a..55e8db8 100755
--- a/python/examples/proton_tornado.py
+++ b/python/examples/proton_tornado.py
@@ -91,8 +91,11 @@ class TornadoLoopHandler:
self.loop.add_callback(self._stop)
def _stop(self):
- self.reactor.stop()
- self.loop.stop()
+ # We could have received a new selectable since we sent the stop
+ if self.count == 0:
+ self.reactor.stop()
+ self.loop.stop()
+
class Container(object):
def __init__(self, *handlers, **kwargs):
diff --git a/python/examples/test_examples.py b/python/examples/test_examples.py
index 01bcc94..8df68ec 100644
--- a/python/examples/test_examples.py
+++ b/python/examples/test_examples.py
@@ -69,6 +69,12 @@ class ExamplesTest(unittest.TestCase):
def test_helloworld_blocking(self):
self.test_helloworld('helloworld_blocking.py')
+ def test_helloworld_tornado(self):
+ self.test_helloworld('helloworld_tornado.py')
+
+ def test_helloworld_direct_tornado(self):
+ self.test_helloworld('helloworld_direct_tornado.py')
+
def test_simple_send_recv(self, recv='simple_recv.py', send='simple_send.py'):
with Popen([recv]) as r:
with Popen([send]):
diff --git a/python/proton/_handlers.py b/python/proton/_handlers.py
index 3525ffb..5ff45dd 100644
--- a/python/proton/_handlers.py
+++ b/python/proton/_handlers.py
@@ -1396,26 +1396,33 @@ class ConnectSelectable(Selectable):
def writable(self):
e = self._delegate.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
t = self._transport
+
+ # Always cleanup this ConnectSelectable: either we failed or created a new one
+ # Do it first to ensure the socket gets deregistered before being registered again
+ # in the case of connecting
+ self.terminate()
+ self._transport = None
+ self.update()
+
if e == 0:
log.debug("Connection succeeded")
+
+ # Disassociate from the socket (which will be passed on)
+ self.release()
+
s = self._reactor.selectable(delegate=self._delegate)
s._transport = t
t._selectable = s
self._iohandler.update(t, s, t._reactor.now)
- # Disassociate from the socket (which has been passed on)
- self._delegate = None
- self.terminate()
- self._transport = None
- self.update()
return
elif e == errno.ECONNREFUSED:
if len(self._addrs) > 0:
log.debug("Connection refused: trying next transport address: %s", self._addrs[0])
+
sock = IO.connect(self._addrs[0])
- self._addrs = self._addrs[1:]
- self._delegate.close()
- self._delegate = sock
+ # New ConnectSelectable for the new socket with rest of addresses
+ ConnectSelectable(sock, self._reactor, self._addrs[1:], t, self._iohandler)
return
else:
log.debug("Connection refused, but tried all transport addresses")
@@ -1426,6 +1433,3 @@ class ConnectSelectable(Selectable):
t.close_tail()
t.close_head()
- self.terminate()
- self._transport = None
- self.update()
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[qpid-proton] 03/03: PROTON-2156: [Python] Fix client_http for
changes in tornado
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit 9c7b3fceaa896117f9a04e833e833bcf4a28a99d
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Fri Jan 17 15:39:56 2020 -0500
PROTON-2156: [Python] Fix client_http for changes in tornado
---
python/examples/client_http.py | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/python/examples/client_http.py b/python/examples/client_http.py
index bf65639..f756740 100755
--- a/python/examples/client_http.py
+++ b/python/examples/client_http.py
@@ -21,6 +21,8 @@
from __future__ import print_function
import tornado.ioloop
import tornado.web
+from tornado.gen import coroutine
+from tornado.concurrent import Future
from proton import Message
from proton.handlers import MessagingHandler
from proton_tornado import Container
@@ -51,22 +53,24 @@ class Client(MessagingHandler):
def on_message(self, event):
if self.sent:
- request, handler = self.sent.pop(0)
+ request, future = self.sent.pop(0)
print("%s => %s" % (request, event.message.body))
- handler(event.message.body)
+ future.set_result(event.message.body)
self.do_request()
def do_request(self):
if self.pending and self.reply_address and self.sender.credit:
- request, handler = self.pending.pop(0)
- self.sent.append((request, handler))
+ request, future = self.pending.pop(0)
+ self.sent.append((request, future))
req = Message(reply_to=self.reply_address, body=request)
self.sender.send(req)
- def request(self, body, handler):
- self.pending.append((body, handler))
+ def request(self, body):
+ future = Future()
+ self.pending.append((body, future))
self.do_request()
self.container.touch()
+ return future
class ExampleHandler(tornado.web.RequestHandler):
def initialize(self, client):
@@ -77,17 +81,14 @@ class ExampleHandler(tornado.web.RequestHandler):
self._write_form()
self._write_close()
- @tornado.web.asynchronous
+ @coroutine
def post(self):
- client.request(self.get_body_argument("message"), lambda x: self.on_response(x))
-
- def on_response(self, body):
+ response = yield self.client.request(self.get_body_argument("message"))
self.set_header("Content-Type", "text/html")
self._write_open()
self._write_form()
- self.write("Response: " + body)
+ self.write("Response: " + response)
self._write_close()
- self.finish()
def _write_open(self):
self.write('<html><body>')
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[qpid-proton] 01/03: PROTON-2156: [Python] Simplify selectable
protocol - Selectable now encapsulates all the events it sends it uses the
reactor to send events - Simplified delegate logic
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit 900347e38fb5ef559bcfae89ff74a0a2503da2e5
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Thu Jan 16 13:44:06 2020 -0500
PROTON-2156: [Python] Simplify selectable protocol
- Selectable now encapsulates all the events it sends
it uses the reactor to send events
- Simplified delegate logic
---
python/examples/proton_tornado.py | 2 +-
python/proton/_events.py | 1 -
python/proton/_handlers.py | 10 ++++------
python/proton/_reactor.py | 19 ++++++-------------
python/proton/_selectable.py | 29 +++++++++++++++++------------
5 files changed, 28 insertions(+), 33 deletions(-)
diff --git a/python/examples/proton_tornado.py b/python/examples/proton_tornado.py
index 751b3ef..8829a4a 100755
--- a/python/examples/proton_tornado.py
+++ b/python/examples/proton_tornado.py
@@ -85,7 +85,7 @@ class TornadoLoopHandler:
sel = event.context
if sel.fileno() >= 0:
self.loop.remove_handler(sel.fileno())
- sel.release()
+ sel.close()
self.count -= 1
if self.count == 0:
self.loop.add_callback(self._stop)
diff --git a/python/proton/_events.py b/python/proton/_events.py
index 59c3ae5..f1f54e7 100644
--- a/python/proton/_events.py
+++ b/python/proton/_events.py
@@ -399,7 +399,6 @@ class Event(EventBase):
reactor.
"""
-
SELECTABLE_INIT = _internal("selectable_init")
SELECTABLE_UPDATED = _internal("selectable_updated")
SELECTABLE_READABLE = _internal("selectable_readable")
diff --git a/python/proton/_handlers.py b/python/proton/_handlers.py
index 443f728..3525ffb 100644
--- a/python/proton/_handlers.py
+++ b/python/proton/_handlers.py
@@ -1136,7 +1136,7 @@ class PythonIO:
sel = event.context
if sel.is_terminal:
self.selectables.remove(sel)
- sel.release()
+ sel.close()
def on_reactor_quiesced(self, event):
reactor = event.reactor
@@ -1198,7 +1198,7 @@ class IOHandler(Handler):
s = event.selectable
self._selector.remove(s)
s._reactor._selectables -= 1
- s.release()
+ s.close()
def on_reactor_quiesced(self, event):
r = event.reactor
@@ -1337,10 +1337,7 @@ class IOHandler(Handler):
sock = IO.connect(addrs[0])
# At this point we need to arrange to be called back when the socket is writable
- connector = ConnectSelectable(sock, reactor, addrs[1:], t, self)
- connector.collect(reactor._collector)
- connector.writing = True
- connector.push_event(connector, Event.SELECTABLE_INIT)
+ ConnectSelectable(sock, reactor, addrs[1:], t, self)
# TODO: Don't understand why we need this now - how can we get PN_TRANSPORT until the connection succeeds?
t._selectable = None
@@ -1388,6 +1385,7 @@ class IOHandler(Handler):
class ConnectSelectable(Selectable):
def __init__(self, sock, reactor, addrs, transport, iohandler):
super(ConnectSelectable, self).__init__(sock, reactor)
+ self.writing = True
self._addrs = addrs
self._transport = transport
self._iohandler = iohandler
diff --git a/python/proton/_reactor.py b/python/proton/_reactor.py
index c93b55d..2dd2704 100644
--- a/python/proton/_reactor.py
+++ b/python/proton/_reactor.py
@@ -44,7 +44,7 @@ from ._selectable import Selectable
from ._handlers import OutgoingMessageHandler, IOHandler
-from ._io import IO, PN_INVALID_SOCKET
+from ._io import IO
from . import _compat
from ._compat import queue
@@ -83,15 +83,11 @@ class Task(object):
def container(self):
return self._reactor
+
class TimerSelectable(Selectable):
- def __init__(self, reactor, collector):
+ def __init__(self, reactor):
super(TimerSelectable, self).__init__(None, reactor)
- self.collect(collector)
- collector.put(self, Event.SELECTABLE_INIT)
-
- def fileno(self):
- return PN_INVALID_SOCKET
def readable(self):
pass
@@ -196,7 +192,7 @@ class Reactor(object):
def start(self):
self.push_event(self, Event.REACTOR_INIT)
- self._selectable = TimerSelectable(self, self._collector)
+ self._selectable = TimerSelectable(self)
self._selectable.deadline = self.timer_deadline
# TODO set up fd to read for wakeups - but problematic on windows
#self._selectable.fileno(self._wakeup[0])
@@ -252,7 +248,7 @@ class Reactor(object):
else:
if self._selectable:
self._selectable.terminate()
- self.update(self._selectable)
+ self._selectable.update()
self._selectable = None
else:
if self._previous is not Event.REACTOR_FINAL:
@@ -365,9 +361,7 @@ class Reactor(object):
if delegate is None:
delegate = handler
result = Selectable(delegate, self)
- result.collect(self._collector)
result.handler = handler
- result.push_event(result, Event.SELECTABLE_INIT)
return result
def update(self, selectable):
@@ -884,9 +878,8 @@ class Acceptor(Handler):
def close(self):
if not self._selectable.is_terminal:
- IO.close(self._selectable)
self._selectable.terminate()
- self._reactor.update(self._selectable)
+ self._selectable.update()
def on_selectable_readable(self, event):
s = event.selectable
diff --git a/python/proton/_selectable.py b/python/proton/_selectable.py
index 1839953..678d96b 100644
--- a/python/proton/_selectable.py
+++ b/python/proton/_selectable.py
@@ -21,6 +21,8 @@ from __future__ import absolute_import
from ._events import Event
+from ._io import PN_INVALID_SOCKET
+
class Selectable(object):
@@ -30,19 +32,23 @@ class Selectable(object):
self.writing = False
self._deadline = 0
self._terminal = False
+ self._released = False
self._terminated = False
- self._collector = None
self._reactor = reactor
+ self.push_event(self, Event.SELECTABLE_INIT)
- def release(self):
- if self._delegate:
+ def close(self):
+ if self._delegate and not self._released:
self._delegate.close()
- def __getattr__(self, name):
+ def fileno(self):
if self._delegate:
- return getattr(self._delegate, name)
+ return self._delegate.fileno()
else:
- return None
+ return PN_INVALID_SOCKET
+
+ def __getattr__(self, name):
+ return getattr(self._delegate, name)
def _get_deadline(self):
tstamp = self._deadline
@@ -59,12 +65,8 @@ class Selectable(object):
deadline = property(_get_deadline, _set_deadline)
- def collect(self, collector):
- self._collector = collector
-
- def push_event(self, context, type):
- if self._collector:
- self._collector.put(context, type)
+ def push_event(self, context, etype):
+ self._reactor.push_event(context, etype)
def update(self):
if not self._terminated:
@@ -89,3 +91,6 @@ class Selectable(object):
def terminate(self):
self._terminal = True
+
+ def release(self):
+ self._released = True
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org