summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/asyncpg.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/asyncpg.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/asyncpg.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/asyncpg.py b/lib/sqlalchemy/dialects/postgresql/asyncpg.py
index a84bece4f..4cc04d20a 100644
--- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py
+++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py
@@ -741,6 +741,12 @@ class AsyncAdapt_asyncpg_connection(AdaptedConnection):
else:
self.isolation_level = self._isolation_setting
+ def ping(self):
+ try:
+ _ = self.await_(self._connection.fetchrow(";"))
+ except Exception as error:
+ self._handle_exception(error)
+
def set_isolation_level(self, level):
if self._started:
self.rollback()
@@ -996,6 +1002,17 @@ class PGDialect_asyncpg(PGDialect):
util.coerce_kw_type(opts, "port", int)
return ([], opts)
+ def do_ping(self, dbapi_connection):
+ try:
+ dbapi_connection.ping()
+ except self.dbapi.Error as err:
+ if self.is_disconnect(err, dbapi_connection, None):
+ return False
+ else:
+ raise
+ else:
+ return True
+
@classmethod
def get_pool_class(cls, url):