db.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:ravel 作者: ravel-net 项目源码 文件源码
def num_connections(self):
        """Returns the number of existing connections to the database.  If
           there are >1 connections, a new Ravel base implementation cannot be
           loaded into the database.
           returns: the number of existing connections to the database"""
        try:
            self.cursor.execute("SELECT * FROM pg_stat_activity WHERE "
                                "datname='{0}'".format(self.name))

            # ignore cursor connection
            return len(self.cursor.fetchall()) - 1
        except psycopg2.DatabaseError, e:
            logger.warning("error loading schema: %s", self.fmt_errmsg(e))

        return 0
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号