-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
52 lines (38 loc) · 909 Bytes
/
test.py
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
import gevent
from gevent import monkey
monkey.patch_all()
from gevent import Greenlet
import etcd
import random
import threading
client = etcd.Client()
def watchTask():
print 'now watch...'
def do():
rVal = client.read('/nodes/abc', wait=True)
print "!!!!!!!!!!!!!!!!!!!!!ChangeVal %s" % rVal
t = threading.Thread(target=do)
t.start()
print 'now watch2...'
print 'watch finished...'
def task1():
for i in range(10):
print 'now set...'
setVal = random.randint(0,99)
print 'real set - %s' % setVal
client.set('/nodes/abc', setVal)
print 'set ok - %s' % setVal
print('Finished!!!!!!!')
def task2():
def asyncGet():
val = client.read('/nodes/abc')
print 'get ok - %s' % val
for i in range(10):
print 'now get....'
gevent.spawn(asyncGet).join()
print('Finished!!!!!!! Task2')
gevent.joinall([
gevent.spawn(watchTask),
gevent.spawn(task1),
gevent.spawn(task2)
])