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
评论列表
文章目录