File: timers.py

package info (click to toggle)
circuits 3.2.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,980 kB
  • sloc: python: 17,583; javascript: 3,226; makefile: 100
file content (51 lines) | stat: -rwxr-xr-x 1,070 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
"""
Simple Timers

A trivial simple example of using circuits and timers.
"""

from circuits import Component, Event, Timer


class App(Component):
    def hello(self):
        """
        hello Event handler

        Fired once in 5 seconds.
        """
        print('Hello World')

    def foo(self):
        """
        foo Event handler

        Fired every 1 seconds.
        """
        print('Foo')

    def bar(self):
        """
        bar Event handler

        Fired every 3 seconds.
        """
        print('Bar')

    def started(self, component):
        """
        started Event handler

        Setup 3 timers at 5, 1 and 3 seconds.
        The 2nd two timers are persitent meaning that
        they are fired repeatedly every 1 and 3 seconds
        respectively.
        """
        # Timer(seconds, event, persist=False)
        Timer(5, Event.create('hello')).register(self)
        Timer(1, Event.create('foo'), persist=True).register(self)
        Timer(3, Event.create('bar'), persist=True).register(self)


App().run()