Menu Search

recurring_timer_tornado.py

from __future__ import print_function
import time
from proton.reactor import Handler
from proton_tornado import TornadoLoop

class Recurring(Handler):
    def __init__(self, period):
        self.period = period

    def on_start(self, event):
        self.container = event.container
        self.container.schedule(time.time() + self.period, subject=self)

    def on_timer(self, event):
        print("Tick...")
        self.container.schedule(time.time() + self.period, subject=self)

try:
    container = TornadoLoop(Recurring(1.0))
    container.run()
except KeyboardInterrupt:
    container.stop()
    print()

Download this file