Closed fatpo closed 7 years ago
i got it.... two conn, life time, make it clear.... 就是说跨库查询的时候,conn的生命周期要弄对...
ERROR CODE:
# 先获取禅在app的文章运营列表
pool = self.pools[0]
with (yield pool.Connection()) as conn:
yield conn.commit()
article_infos = yield ArticleDao.get_articles(self.context, conn, page, white_list=settings.RECOMMEND_WHITE_LIST)
logging.info("app文章len=%s" % len(article_infos))
zzh_pool = self.pools[1]
# 再跟进app的文章列表一个个去自在家查
with (yield zzh_pool.Connection()) as zzh_conn:
yield zzh_conn.commit()
for i in article_infos:
zzh_article_info = yield ZZHArticleDao.get_article(self.context, zzh_conn, i.zzh_article_id)
if not zzh_article_info:
logging.error("奇怪,自在家文章不存在: %s" % i.zzh_article_id)
continue
pb_article = self.rsp_info.rsp.articles.add()
ArticleService.wrap_info_to_pb(zzh_article_info, pb_article)
# 文章标题和图片改成禅在后台运营的
pb_article.title = i.title
img_info = yield ImgDao.get(self.context, conn, i.img_id)
pb_article.img_url = settings.QINIU_HTTPS_HOST + img_info.imgurl if img_info else zzh_article_info.pic
CORRECT CODE:
# 先获取禅在app的文章运营列表
pool = self.pools[0]
zzh_pool = self.pools[1]
with (yield pool.Connection()) as conn:
yield conn.commit()
article_infos = yield ArticleDao.get_articles(self.context, conn, page, white_list=settings.RECOMMEND_WHITE_LIST)
logging.info("app文章len=%s" % len(article_infos))
# 再跟进app的文章列表一个个去自在家查
with (yield zzh_pool.Connection()) as zzh_conn:
yield zzh_conn.commit()
for i in article_infos:
zzh_article_info = yield ZZHArticleDao.get_article(self.context, zzh_conn, i.zzh_article_id)
if not zzh_article_info:
logging.error("奇怪,自在家文章不存在: %s" % i.zzh_article_id)
continue
pb_article = self.rsp_info.rsp.articles.add()
ArticleService.wrap_info_to_pb(zzh_article_info, pb_article)
# 文章标题和图片改成禅在后台运营的
pb_article.title = i.title
img_info = yield ImgDao.get(self.context, conn, i.img_id)
pb_article.img_url = settings.QINIU_HTTPS_HOST + img_info.imgurl if img_info else zzh_article_info.pic
a bug make me confuse, the whole process of this bug like:
it often comes when i use conn.commit() without yield
but this time, i have no idea...
my log: