Skip to content

Commit 45c2ed0

Browse files
committed
Update examples
1 parent dd44a8e commit 45c2ed0

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
File renamed without changes.
File renamed without changes.

example/pool2.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
from __future__ import print_function
3+
4+
import random
5+
from tornado import ioloop, gen
6+
from tornado_mysql import pools
7+
8+
9+
pools.DEBUG = True
10+
11+
12+
POOL = pools.Pool(
13+
dict(host='127.0.0.1', port=3306, user='root', passwd='', db='mysql'),
14+
max_idle_connections=2,
15+
max_recycle_sec=3,
16+
max_open_connections=5,
17+
)
18+
19+
20+
@gen.coroutine
21+
def worker(n):
22+
for i in range(20):
23+
t = random.random() * 5
24+
print(n, "sleeping", t, "seconds")
25+
cur = yield POOL.execute("SELECT SLEEP(%s)", (t,))
26+
print(n, cur.fetchall())
27+
yield gen.sleep(t)
28+
29+
30+
@gen.coroutine
31+
def main():
32+
workers = [worker(i) for i in range(10)]
33+
yield workers
34+
35+
36+
ioloop.IOLoop.current().run_sync(main)
37+
print(POOL._opened_conns)
38+

0 commit comments

Comments
 (0)