Q:

Why doesn't my tornado application work?(tornado-blog with aiomysql)

import tornado.ioloop
import tornado.web
import tornado.options
import tornado.locks
import os.path

from tornado.options import define, options
from aiomysql import create_pool

define("port", default=8080, help="run on the given port", type=int)
define("db_host", default="localhost", help="blog database host")
define("db_port", default=3306, help="blog database port")
define("db_database", default="{db_name}", help="blog database name")
define("db_user", default="{db_user}", help="blog database user")
define("db_password", default="{password}", help="blog database password")

async def maybe_create_tables(db):
    async with db.acquire() as conn:
        async with conn.cursor() as cur:
            try:
                await cur.execute("SELECT COUNT(*) FROM user LIMIT 1")
                await cur.fetchone()
            except Exception as e:
                with open("schema.sql") as f:
                    schema = f.read()
                    await cur.execute(schema)

class Application(tornado.web.Application):
    def __init__(self, db):
        self.db = db
        handlers = [
            (r"/", HomeHandler),
            (r".*", BaseHandler)
        ]
        settings = dict(
            debug=True
        )
        super(Application, self).__init__(handlers, **settings)

class BaseHandler(tornado.web.RequestHandler):
   def set_default_headers(self):
        self.set_header("Server", "tornado")

class HomeHandler(BaseHandler):
    async def get(self):
        self.write("hello")

async def main():
    tornado.options.parse_command_line()

    async with create_pool(
        host=options.db_host,
        port=options.db_port,
        user=options.db_user,
        password=options.db_password,
        db=options.db_database,
    ) as db:
        await maybe_create_tables(db)
        app = Application()
        app.listen(options.port)

    shutdown_event = tornado.locks.Event()
    await shutdown_event.wait()

if __name__ == "__main__":
    tornado.ioloop.IOLoop.current().run_sync(main)

I copied these codes from here(https://github.com/xzhdream/tornado-blog-aiomysql/blob/master/blog.py), but it does not work.
When I run this app, there's no output error but console got freezed. Mysql and Mysql User setting must be done properly. I checked it many times.

A:

Your Application.__init__ takes a db argument, but you're not passing one when calling Application. I don't know why you're not getting any error tracebacks about this issue. 
The await shutdown_event.wait() call is outside the async with create_pool, so the database connection pool will be closed as soon as initialization is complete and won't be available while the server is running. Indent these lines so they are included in the async with block. 

