fatpo
版本: tormysql==0.2.9 tornado==4.2 ``` 2018-02-01 17:11:38,443 GetGongxiuList.py-58 [ERROR] If cursor not read all data, the connection next query is error. Traceback (most recent call last): File "/data/www/myapp/biz_handlers/gongxiu/GetGongxiuList.py", line 43, in run yield GongxiuService.wrap_info_to_pb(conn, gx_info, pb_gx) File "/data/python_venv/chanzai_venv/lib/python2.7/site-packages/tornado/gen.py", line 870, in run value = future.result() File "/data/python_venv/chanzai_venv/lib/python2.7/site-packages/tornado/concurrent.py", line 215, in result raise_exc_info(self._exc_info) File "/data/python_venv/chanzai_venv/lib/python2.7/site-packages/tornado/gen.py", line 879, in run yielded = self.gen.send(value) File "/data/www/myapp/service/gongxiu/Gongxiu.py", line 46, in wrap_info_to_pb pb.creator.avatar = settings.QINIU_HTTP_HOST + '/' + settings.QINIU_DEFAULT_HEAD_IMG_KEY File "/data/python_venv/chanzai_venv/lib/python2.7/site-packages/tormysql/cursor.py", line 76, in __exit__ raise CursorNotReadAllDataError("If cursor not read all data, the connection next query is error.") CursorNotReadAllDataError: If cursor not read all data, the connection next query is error. 2018-02-01 17:11:38,444 web.py-1908 [INFO] 200 POST /api?type=json (127.0.0.1) 62.65ms ``` 我的代码如下: 外层: ``` with (yield pool.Connection()) as conn: yield conn.commit() for gx_info in gx_infos: pb_gx = self.rsp_info.rsp.gongxius.add() yield GongxiuService.wrap_info_to_pb(conn, gx_info, pb_gx) ``` 内层: ``` @classmethod @tornado.gen.coroutine def wrap_info_to_pb(cls, conn, info, pb): with conn.cursor() as cursor: # 补充用户头像 + 用户名 sql = "select nick_name, user_name, head_img from %s.user where `status`=0 and id=%s" % ( settings.db_zizaihome_name, info.creator_id) logging.info(sql) yield cursor.execute(sql) item = cursor.fetchone() if item: if item['nick_name']: pb.creator.username = item['nick_name'] elif item['user_name']: pb.creator.username = item['user_name'] if item['head_img']: pb.creator.avatar = item['head_img'] else: pb.creator.avatar = settings.QINIU_HTTP_HOST + '/' + settings.QINIU_DEFAULT_HEAD_IMG_KEY ``` 在我上洗手间之前,bug稳定重现,每一次都是执行到以下sql出错: ``` select user_name, nick_name, head_img from dev.user where `status`=0 and id=100001 ``` 郁闷的我出去上了个洗手间,然后回来,把sql改成: ``` select nick_name, user_name, head_img from dev.user where `status`=0 and id=100001 ``` 再也没出现bug。。。 为什么呢...不就是user_name和nick_name的顺序换了一下而已嘛??? orz..