当前位置: 首页>>代码示例>>Python>>正文


Python coordination.raise_with_cause函数代码示例

本文整理汇总了Python中tooz.coordination.raise_with_cause函数的典型用法代码示例。如果您正苦于以下问题:Python raise_with_cause函数的具体用法?Python raise_with_cause怎么用?Python raise_with_cause使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了raise_with_cause函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _lock

        def _lock():
            # NOTE(sileht): mysql-server (<5.7.5) allows only one lock per
            # connection at a time:
            #  select GET_LOCK("a", 0);
            #  select GET_LOCK("b", 0); <-- this release lock "a" ...
            # Or
            #  select GET_LOCK("a", 0);
            #  select GET_LOCK("a", 0); release and lock again "a"
            #
            # So, we track locally the lock status with self.acquired
            if self.acquired is True:
                if blocking:
                    raise _retry.Retry
                return False

            try:
                with self._conn as cur:
                    cur.execute("SELECT GET_LOCK(%s, 0);", self.name)
                    # Can return NULL on error
                    if cur.fetchone()[0] is 1:
                        self.acquired = True
                        return True
            except pymysql.MySQLError as e:
                coordination.raise_with_cause(
                    coordination.ToozError,
                    encodeutils.exception_to_unicode(e),
                    cause=e)

            if blocking:
                raise _retry.Retry
            return False
开发者ID:aarefiev22,项目名称:tooz,代码行数:31,代码来源:mysql.py

示例2: get

 def get(self, timeout=10):
     try:
         return self._fut.result(timeout=timeout)
     except futures.TimeoutError as e:
         coordination.raise_with_cause(coordination.OperationTimedOut,
                                       utils.exception_message(e),
                                       cause=e)
开发者ID:cloudnull,项目名称:tooz,代码行数:7,代码来源:ipc.py

示例3: get_connection

    def get_connection(parsed_url, options):
        host = parsed_url.hostname
        port = parsed_url.port or MySQLLock.MYSQL_DEFAULT_PORT
        dbname = parsed_url.path[1:]
        username = parsed_url.username
        password = parsed_url.password
        unix_socket = options.get("unix_socket")

        try:
            if unix_socket:
                return pymysql.Connect(unix_socket=unix_socket,
                                       port=port,
                                       user=username,
                                       passwd=password,
                                       database=dbname)
            else:
                return pymysql.Connect(host=host,
                                       port=port,
                                       user=username,
                                       passwd=password,
                                       database=dbname)
        except (pymysql.err.OperationalError, pymysql.err.InternalError) as e:
            coordination.raise_with_cause(coordination.ToozConnectionError,
                                          encodeutils.exception_to_unicode(e),
                                          cause=e)
开发者ID:aarefiev22,项目名称:tooz,代码行数:25,代码来源:mysql.py

示例4: _translate_failures

def _translate_failures():
    try:
        yield
    except (EnvironmentError, voluptuous.Invalid) as e:
        coordination.raise_with_cause(coordination.ToozError,
                                      encodeutils.exception_to_unicode(e),
                                      cause=e)
开发者ID:csfreak,项目名称:tooz,代码行数:7,代码来源:file.py

示例5: _translate_failures

def _translate_failures():
    try:
        yield
    except EnvironmentError as e:
        coordination.raise_with_cause(coordination.ToozError,
                                      utils.exception_message(e),
                                      cause=e)
开发者ID:cloudnull,项目名称:tooz,代码行数:7,代码来源:file.py

示例6: loads

def loads(blob, excp_cls=coordination.SerializationError):
    """Deserializes provided data using msgpack (from a prior byte string)."""
    try:
        return msgpackutils.loads(blob)
    except (msgpack.UnpackException, ValueError) as e:
        coordination.raise_with_cause(excp_cls, exception_message(e),
                                      cause=e)
开发者ID:cloudnull,项目名称:tooz,代码行数:7,代码来源:utils.py

示例7: dumps

def dumps(data, excp_cls=coordination.SerializationError):
    """Serializes provided data using msgpack into a byte string."""
    try:
        return msgpackutils.dumps(data)
    except (msgpack.PackException, ValueError) as e:
        coordination.raise_with_cause(excp_cls, exception_message(e),
                                      cause=e)
开发者ID:cloudnull,项目名称:tooz,代码行数:7,代码来源:utils.py

示例8: _start

 def _start(self):
     self._executor = futures.ThreadPoolExecutor(max_workers=1)
     try:
         self._client = self._make_client(self._parsed_url, self._options,
                                          self.timeout)
     except exceptions.RedisError as e:
         coordination.raise_with_cause(coordination.ToozConnectionError,
                                       utils.exception_message(e),
                                       cause=e)
     else:
         # Ensure that the server is alive and not dead, this does not
         # ensure the server will always be alive, but does insure that it
         # at least is alive once...
         with _translate_failures():
             self._server_info = self._client.info()
         # Validate we have a good enough redis version we are connected
         # to so that the basic set of features we support will actually
         # work (instead of blowing up).
         new_enough, redis_version = self._check_fetch_redis_version(
             self.MIN_VERSION)
         if not new_enough:
             raise tooz.NotImplemented("Redis version greater than or"
                                       " equal to '%s' is required"
                                       " to use this driver; '%s' is"
                                       " being used which is not new"
                                       " enough" % (self.MIN_VERSION,
                                                    redis_version))
         self.heartbeat()
         self._started = True
开发者ID:yunjianfei,项目名称:tooz,代码行数:29,代码来源:redis.py

示例9: wrapper

 def wrapper(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except requests.exceptions.RequestException as e:
         coordination.raise_with_cause(coordination.ToozConnectionError,
                                       encodeutils.exception_to_unicode(e),
                                       cause=e)
开发者ID:flyingmeat,项目名称:tooz,代码行数:7,代码来源:etcd.py

示例10: _translating_cursor

def _translating_cursor(conn):
    try:
        with conn.cursor() as cur:
            yield cur
    except psycopg2.Error as e:
        coordination.raise_with_cause(coordination.ToozError,
                                      _format_exception(e),
                                      cause=e)
开发者ID:yunjianfei,项目名称:tooz,代码行数:8,代码来源:pgsql.py

示例11: release

 def release(self):
     try:
         with self._conn as cur:
             cur.execute("SELECT RELEASE_LOCK(%s);", self.name)
             cur.fetchone()
             self.acquired = False
     except pymysql.MySQLError as e:
         coordination.raise_with_cause(coordination.ToozError,
                                       utils.exception_message(e),
                                       cause=e)
开发者ID:yunjianfei,项目名称:tooz,代码行数:10,代码来源:mysql.py

示例12: release

 def release(self):
     if not self.acquired:
         return False
     try:
         with self._conn as cur:
             cur.execute("SELECT RELEASE_LOCK(%s);", self.name)
             cur.fetchone()
             self.acquired = False
             return True
     except pymysql.MySQLError as e:
         coordination.raise_with_cause(coordination.ToozError, encodeutils.exception_to_unicode(e), cause=e)
开发者ID:flyingmeat,项目名称:tooz,代码行数:11,代码来源:mysql.py

示例13: get

 def get(self, timeout=10):
     try:
         # Late translate the common failures since the file driver
         # may throw things that we can not catch in the callbacks where
         # it is used.
         with _translate_failures():
             return self._fut.result(timeout=timeout)
     except futures.TimeoutError as e:
         coordination.raise_with_cause(coordination.OperationTimedOut,
                                       utils.exception_message(e),
                                       cause=e)
开发者ID:cloudnull,项目名称:tooz,代码行数:11,代码来源:file.py

示例14: get

 def get(self, timeout=10):
     try:
         # Late translate the common failures since the redis client
         # may throw things that we can not catch in the callbacks where
         # it is used (especially one that uses the transaction
         # method).
         with _translate_failures():
             return self._fut.result(timeout=timeout)
     except futures.TimeoutError as e:
         coordination.raise_with_cause(coordination.OperationTimedOut,
                                       encodeutils.exception_to_unicode(e),
                                       cause=e)
开发者ID:flyingmeat,项目名称:tooz,代码行数:12,代码来源:redis.py

示例15: wrapper

 def wrapper(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except ValueError as e:
         # Typically json decoding failed for some reason.
         coordination.raise_with_cause(coordination.ToozError,
                                       encodeutils.exception_to_unicode(e),
                                       cause=e)
     except requests.exceptions.RequestException as e:
         coordination.raise_with_cause(coordination.ToozConnectionError,
                                       encodeutils.exception_to_unicode(e),
                                       cause=e)
开发者ID:rocknio,项目名称:tooz,代码行数:12,代码来源:etcd.py


注:本文中的tooz.coordination.raise_with_cause函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。