Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
from __future__ import print_function
import time
from circuits import Component, Event, Debugger
times = []
class doit(Event):
"""doit Event"""
class terminate(Event):
"""terminate Event"""
class App(Component):
def init(self):
self.interval = 5
self.last = 0
self.count = 0
def doit(self, origin):
times.append(("%s from A at %.03f" % (origin, time.time())))
self.count += 1
self.last = time.time()
def generate_events(self, event):
if self.count >= 5:
event.reduce_time_left(0)
self.fire(terminate())
return
if self.last + self.interval < time.time():
event.reduce_time_left(0)
self.fire(doit('ge'))
else:
event.reduce_time_left(time.time() - self.last + self.interval)
def terminate(self):
raise SystemExit(0)
(Debugger() + App()).run()
print("\n".join(times))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.