Skip to content

Instantly share code, notes, and snippets.

@jettify
Last active March 23, 2016 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jettify/36584872aabaa2e5f8bb to your computer and use it in GitHub Desktop.
Save jettify/36584872aabaa2e5f8bb to your computer and use it in GitHub Desktop.
@asyncio.coroutine
def do_select(pool, i):
with (yield from pool) as conn:
cur = yield from conn.cursor()
yield from cur.execute("SELECT 10")
yield from cur.close()
@asyncio.coroutine
def test_example(loop):
pool = yield from aiomysql.create_pool(host='127.0.0.1', port=3306,
minsize = 20, maxsize=20
user='root', password='',
db='mysql', loop=loop)
coros = [do_select(pool, i) for i in range(20)]
yield from asyncio.gather(*coros, loop=loop
pool.close()
yield from pool.wait_closed()
loop = asyncio.get_event_loop()
loop.run_until_complete(test_example(loop))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment