Skip to content

Instantly share code, notes, and snippets.

@methane
Last active May 11, 2016 09:02
Show Gist options
  • Save methane/068a269fc804fa2e39a53be3c55e275a to your computer and use it in GitHub Desktop.
Save methane/068a269fc804fa2e39a53be3c55e275a to your computer and use it in GitHub Desktop.
import tornado_mysql
from tornado import ioloop, gen
@gen.coroutine
def main():
print("trying to connect to MySQL")
conn = yield tornado_mysql.connect(host='127.0.0.1', user='root', db='test')
cur = conn.cursor()
yield cur.execute("CREATE TABLE tornado_test (a int)")
query = "INSERT INTO tornado_test (a) values (42)"
yield cur.execute(query) # this is getting executed!
yield cur.close()
yield conn.commit()
yield conn.close_async() # tried conn.close() as well, Both throws an exception:
print('end')
ioloop.IOLoop.current().run_sync(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment