File: synchronized.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 (45 lines) | stat: -rw-r--r-- 565 bytes parent folder | download | duplicates (3)
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
from __future__ import with_statement
import threading
import kaa

class Test(object):

    def foo(self):
        with kaa.synchronized(self):
            print 5

    @kaa.synchronized()
    def bar(self, x, y):
        print 1, x, y


# threading.Lock does NOT work
lock = threading.RLock()
@kaa.synchronized(lock)
def foo():
    print 6

t = Test()

@kaa.synchronized(t)
def bar(x):
    print 7, x

@kaa.synchronized()
def zap(x):
    print 9, x

@kaa.synchronized()
def baz():
    print 10

t.bar(5, 9)
t.foo()

t2 = Test()
t2.foo()

foo()
bar(8)
zap(8)
baz()