File: decorator.py

package info (click to toggle)
kaa-base 0.6.0%2Bsvn4596-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 2,348 kB
  • ctags: 3,068
  • sloc: python: 11,094; ansic: 1,862; makefile: 74
file content (57 lines) | stat: -rw-r--r-- 1,169 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
52
53
54
55
56
57
from kaa import timed, OneShotTimer, main, \
     is_mainthread, threaded, MAINTHREAD, POLICY_ONCE, POLICY_RESTART


class Foo(object):

    @timed(0.1, policy=POLICY_ONCE)
    def poll(self, x):
        if not x:
            return False
        y = x.pop(0)
        print '1', y
        return True

    @timed(0.1, policy=POLICY_ONCE)
    def poll2(self, x):
        if not x:
            return False
        y = x.pop(0)
        print '2', y
        return True

    @threaded('name')
    def foo(self):
        print 'foo is mainthread:', is_mainthread()
        self.bar()
        
    @threaded(MAINTHREAD)
    def bar(self):
        print 'bar is mainthread:', is_mainthread()
        

@timed(0.1, policy=POLICY_RESTART)
def poll(x):
    if not x:
        return False
    y = x.pop(0)
    print y
    return True


@timed(0.1, OneShotTimer, policy=POLICY_RESTART)
def bla(f, msg):
    print msg
    f.foo()
    f.bar()
    
f = Foo()
f.poll([0,1,2,3,4,5])
f.poll2(['a','b','c','d','e','f'])

poll([10,11,12,13,14,15])
bla(f, 'test')
bla(f, 'test2')
OneShotTimer(poll, [20,21,22,23,24]).start(0.3)
OneShotTimer(f.poll, [30,31,32,33,34]).start(0.3)
main.run()