PyMySQL/Tornado-MySQL

How to use Pool? Please get me sample

mtaiyi opened this issue · 4 comments

my code :

#!/usr/bin/env python
from __future__ import print_function
from tornado import ioloop, gen
from tornado_mysql import pools
pools.DEBUG = True
POOL = pools.Pool(
    dict(host='127.0.0.1', port=3306, user='root', passwd='123456', db='lottery'),
    max_idle_connections=1,
    max_recycle_sec=3)

@gen.coroutine
def getAll():
    cur=yield POOL.execute("SELECT redball1 FROM lottery")
    print(cur.fetchall())
@gen.coroutine
def main():
    getAll()

ioloop.IOLoop.current().run_sync(main)
print(POOL._opened_conns)

But print is "0".why

@gen.coroutine
def main():
    getAll()

You forget yield.

@gen.coroutine
def main():
    yield getAll()

Nothing happens when i add yield

Thanks for reporting. Fixed in master.