我正在使用 Python Tornado 运行非阻塞函数,我应该如何传递参数到主函数?
from __future__ import print_function
from tornado import ioloop, gen
import tornado_mysql
import time
@gen.coroutine
def main(index):
conn = yield tornado_mysql.connect(host=db_host, port=3306, user=db_user, passwd=db_psw, db=db_db)
cur = conn.cursor()
sql = 'INSERT INTO `ctp_db`.`if1506` (`bid`) VALUES (%s)'
yield cur.execute(sql, (index))
conn.commit()
cur.close()
conn.close()
ioloop.IOLoop.current().run_sync(main)