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 2019/01/16 18:46:13 UTC

[qpid-proton] branch master updated: PROTON-1991: [Python] Tornado example no longer works - Scheduler example seems to have bit rotted - Small logic error in tornado examples

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


The following commit(s) were added to refs/heads/master by this push:
     new 603ce7a  PROTON-1991: [Python] Tornado example no longer works - Scheduler example seems to have bit rotted - Small logic error in tornado examples
603ce7a is described below

commit 603ce7a7505a0141c90db5e7ec8e4ba40587012c
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Thu Dec 20 17:25:05 2018 -0500

    PROTON-1991: [Python] Tornado example no longer works
    - Scheduler example seems to have bit rotted
    - Small logic error in tornado examples
---
 python/examples/proton_tornado.py          | 10 ++++++++--
 python/examples/recurring_timer_tornado.py | 13 ++++++-------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/python/examples/proton_tornado.py b/python/examples/proton_tornado.py
index 7c787d5..751b3ef 100755
--- a/python/examples/proton_tornado.py
+++ b/python/examples/proton_tornado.py
@@ -22,6 +22,7 @@ import tornado.ioloop
 from proton.reactor import Container as BaseContainer
 from proton.handlers import IOHandler
 
+
 class TornadoLoopHandler:
 
     def __init__(self, loop=None, handler_base=None):
@@ -51,7 +52,9 @@ class TornadoLoopHandler:
             self.loop.add_timeout(sel.deadline, lambda: self._expired(sel))
 
     def _expired(self, sel):
+        self.reactor.mark()
         sel.expired()
+        self._process()
 
     def _process(self):
         self.reactor.process()
@@ -74,13 +77,13 @@ class TornadoLoopHandler:
 
     def on_selectable_updated(self, event):
         sel = event.context
-        if sel.fileno() > 0:
+        if sel.fileno() >= 0:
             self.loop.update_handler(sel.fileno(), self._events(sel))
         self._schedule(sel)
 
     def on_selectable_final(self, event):
         sel = event.context
-        if sel.fileno() > 0:
+        if sel.fileno() >= 0:
             self.loop.remove_handler(sel.fileno())
         sel.release()
         self.count -= 1
@@ -105,6 +108,9 @@ class Container(object):
         self.initialise()
         self.tornado_loop.start()
 
+    def stop(self):
+        self.container.stop()
+
     def touch(self):
         self._process()
 
diff --git a/python/examples/recurring_timer_tornado.py b/python/examples/recurring_timer_tornado.py
index 07ebd26..a9a7579 100755
--- a/python/examples/recurring_timer_tornado.py
+++ b/python/examples/recurring_timer_tornado.py
@@ -19,24 +19,23 @@
 #
 
 from __future__ import print_function
-import time
 from proton.reactor import Handler
-from proton_tornado import TornadoLoop
+from proton_tornado import Container
 
 class Recurring(Handler):
     def __init__(self, period):
         self.period = period
 
-    def on_start(self, event):
+    def on_reactor_init(self, event):
         self.container = event.container
-        self.container.schedule(time.time() + self.period, subject=self)
+        self.container.schedule(self.period, self)
 
-    def on_timer(self, event):
+    def on_timer_task(self, event):
         print("Tick...")
-        self.container.schedule(time.time() + self.period, subject=self)
+        self.container.schedule(self.period, self)
 
 try:
-    container = TornadoLoop(Recurring(1.0))
+    container = Container(Recurring(1.0))
     container.run()
 except KeyboardInterrupt:
     container.stop()


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