zoukankan      html  css  js  c++  java
  • MySQL server has gone away

          最近接手的是个python脚本,通过crontab定期运行,用facebook提供的api抓取数据,处理后再插入到数据库.

    许多人反映这个服务不稳定,抓取的数据不全.

    我在测试的过程中发现,这个脚本开发的时间已经过了很久了,facebook提供的接口数据已经有所调整. 所以会有数据

    格式不对的问题;还有就是在跑了个小时后,会抛出 ‘MySQL server has gone away’ 的异常..

    网上找到的类似案例如下:

    http://stackoverflow.com/questions/8689649/solving-mysql-server-has-gone-away-errors

    http://stackoverflow.com/questions/7942154/mysql-error-2006-mysql-server-has-gone-away

    我观察到操作数据库的类库是torndb,已经过去这么久,会不会这个bug在官方也有反应并修复了呢.

    果不其然..

       1:   
       2:      def _ensure_connected(self):
       3:          # Mysql by default closes client connections that are idle for
       4:          # 8 hours, but the client library does not report this fact until
       5:          # you try to perform a query and it fails.  Protect against this
       6:          # case by preemptively closing and reopening the connection
       7:          # if it has been idle for too long (7 hours by default).
       8:          if (self._db is None or
       9:              (time.time() - self._last_use_time > self.max_idle_time)):
      10:              self.reconnect()
      11:          self._last_use_time = time.time()
  • 相关阅读:
    第二章 万变不离其踪--收割自己的深度图
    2.1 光照系统
    2.2 深度渲染机制
    2.3 来点实际--日照分析实现
    2.4 通视分析
    2.5 Cesium视域分析的实现
    2.6
    第三章 讲真,没几个搞得清楚的经纬度——GIS坐标
    3.1 地理坐标系统
    3.2 渲染坐标系统
  • 原文地址:https://www.cnblogs.com/ms_config/p/3318690.html
Copyright © 2011-2022 走看看