推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
duyuyouci
V2EX  ›  Python

使用 sqlalchemy 和 celery 异步处理数据库查询时,时不时会报错

  •  
  •   duyuyouci · Jun 5, 2019 · 4068 views
    This topic created in 2676 days ago, the information mentioned may be changed or developed.
    时不时会出现 This result object does not return rows. It has been closed automatically.报错,大佬们,请问是什么原因,面向百度和谷歌了半天,也没找到合适的解决办法,求助
    8 replies  •  2019-06-05 17:45:02 +08:00
    duyuyouci
        2
    duyuyouci  
    OP
       Jun 5, 2019
    @liuguichao 感谢🙏,我研究研究
    rogwan
        3
    rogwan  
       Jun 5, 2019 via Android
    @duyuyouci 是在 celery 中直接建立的 sql 连接?还是别的框架的上下文连接?
    robinlovemaggie
        4
    robinlovemaggie  
       Jun 5, 2019
    字面意思:因为(查询)结果对象没有返回数据行,所以被自动关闭。这不像是错误,倒是像是 warning。
    duyuyouci
        5
    duyuyouci  
    OP
       Jun 5, 2019
    @rogwan 是在 celery 中实例化的 session()连接
    @Print.task(bind=True,name="pf_order_print",max_retries=10, base=ErrorMsgTask)
    def print_order(self, order_id, user_id=0):
    from handlers.base.pub_func import OrderPrintBaseFunc
    time_begin = datetime.datetime.now()
    session = DBSession()
    .......
    像这样
    duyuyouci
        6
    duyuyouci  
    OP
       Jun 5, 2019
    @robinlovemaggie 确实不会引起系统错误,但是会影响用户使用😂
    rogwan
        7
    rogwan  
       Jun 5, 2019 via Android
    @duyuyouci 你说的这个问题我没有遇到完全一样的,但是 celery 阻塞假死,导致数据连接出错的情况到是遇到几次。后来处理耗时短的业务就直接 Thread 了,耗时长的加回滚,和异常重连,基本就解决啦。
    liuguichao
        8
    liuguichao  
       Jun 5, 2019
    还有一种可能,遍历 ResultProxy 记录之前,需要先判断一下是否有返回行,直接 for 遍历会出错。
    https://docs.sqlalchemy.org/en/13/core/connections.html?highlight=resultproxy#sqlalchemy.engine.ResultProxy.returns_rows

    returns_rows
    True if this ResultProxy returns rows.
    I.e. if it is legal to call the methods fetchone(), fetchmany() fetchall().
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2322 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 02:11 · PVG 10:11 · LAX 19:11 · JFK 22:11
    ♥ Do have faith in what you're doing.