zoukankan      html  css  js  c++  java
  • Python ORM Storm 源码修改

    安装 storm : pip install storm

    目标:修改 Storm 源代码以支持自动重连
    文件:python安装目录/site-packages/storm/database.py

    在411行添加函数(可以不在这一行,只要是给class Connection添加函数就行):

    def _check_and_reconnect(self):
        if not isinstance(self._database,storm.databases.mysql.MySQL):
            return 0
        try:
            self._raw_connection.ping()
        except Exception,e:
            try:
                self._raw_connection = self._database.raw_connect()
            except Exception,e:
                return 0
        self._state = STATE_CONNECTED
        return 1

    在函数 _ensure_connected(self)中调用上面的函数:

    def _ensure_connected(self):
        """Ensure that we are connected to the database.
    
        If the connection is marked as dead, or if we can't reconnect,
        then raise DisconnectionError.
        """
        if self._blocked:
            raise ConnectionBlockedError("Access to connection is blocked")
        self._check_and_reconnect()  #添加这一行即可,该函数只有这一处改动
        if self._state == STATE_CONNECTED:
            return
        elif self._state == STATE_DISCONNECTED:
            raise DisconnectionError("Already disconnected")
        elif self._state == STATE_RECONNECT:
            try:
                self._raw_connection = self._database.raw_connect()
            except DatabaseError, exc:
                self._state = STATE_DISCONNECTED
                self._raw_connection = None
                raise DisconnectionError(str(exc))
            else:
                self._state = STATE_CONNECTED
    
  • 相关阅读:
    java-线程(一)
    Lucene小例子
    Oracle在Java中事物管理
    sort quick
    static静态数据的初始化
    正则表达式30分钟入门教程
    div遮罩弹框口
    EL表达式
    LeetCode: Invert Binary Tree
    LeetCode: Find the Difference
  • 原文地址:https://www.cnblogs.com/olivetree123/p/5000283.html
Copyright © 2011-2022 走看看