forked from dccmx/stpclient-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync.py
executable file
·45 lines (37 loc) · 1.06 KB
/
async.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
#!/usr/bin/env python
# coding: utf-8
from stpclient import AsyncClient
from stpclient import ioloop
i = 0
def test_callback():
clients = []
def callback(resp):
global i
print resp.error if resp.error is not None else resp.argv
i += 1
if i == 4:
ioloop.IOLoop.instance().stop()
for i in range(2):
clients.append(AsyncClient('localhost', 3370 + i, connect_timeout=2))
for client in clients:
client.call('ping', callback)
client.call('ping', callback)
ioloop.IOLoop.instance().start()
def test_lazy_call():
clients = []
async_response = []
for i in range(10):
clients.append(AsyncClient('localhost', 3370 + i, connect_timeout=2))
for client in clients:
async_response.append(client.lazy_call('ping'))
for resp in async_response:
try:
response = resp.response
print response.argv
except Exception as e:
print str(e)
def main():
#test_callback()
test_lazy_call()
if __name__ == '__main__':
main()