社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

python的lib pymysql停止随机应答

Dennis • 5 年前 • 596 次点击  

我使用pyMysql将数据保存到mysql数据库。我有来自金融市场的定期数据流。我使用cur.executemany一次插入10行。它只对前20-30行运行良好—然后停止写它,并且不抛出任何异常。。

self.queue.append((timestamp,side,size,price))
    if len(self.queue)>=10:
        try:
            self.logger.info("Writing 10 lines to sql..")
            conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='*****', db='sys')
            cur = conn.cursor()
            sqlQ=""" INSERT den_trades (date2 , side, size, price) VALUES (%s,%s,%s,%s)"""
            cur.executemany(sqlQ, self.queue)
            conn.commit()
            conn.close()
            self.queue=[]
        except Exception as e:
            self.logger.warning("Exception while cur.executemany... sys.exc_info()[0]: {}".format(sys.exc_info()[0]))
            self.logger.warning("e.message ".format(e.message))
            template = "An exception of type {0} occurred. Arguments:\n{1!r}"
            message = template.format(type(e).__name__, e.args)
            self.logger.warning(message)
            conn.rollback()

我正试图得到一些例外-但没有人警告。。

奇怪的是-当问题出现时-“向sql写入10行…”仍然对每个tick都很好-self.queue继续增长-因此self.queue=[]永远不会发生。。怎么可能?try的第一个字符串:block仍然有效,但最后一个字符串停止发生。。如果是的话-应该有例外。。。正确的?

还有一件事。我有另一个脚本在同一台机器上运行良好。这个脚本通过pyMysql一次节省了1000行。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52986
 
596 次点击