Skip to content

Commit 309e671

Browse files
committed
Make Connection.is_closed() check if protocol's connection state is alive
1 parent b5b1c99 commit 309e671

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

asyncpg/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ async def set_builtin_type_codec(self, typename, *,
191191
oid, typename, schema, 'scalar', codec_name)
192192

193193
def is_closed(self):
194-
return self._protocol.is_closed() or self._aborted
194+
return not self._protocol.is_connected() or self._aborted
195195

196196
async def close(self):
197197
if self.is_closed():

asyncpg/protocol/protocol.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ cdef class BaseProtocol(CoreProtocol):
240240
def is_closed(self):
241241
return self.closing
242242

243+
def is_connected(self):
244+
return not self.closing and self.con_status == CONNECTION_OK
245+
243246
def abort(self):
244247
if self.closing:
245248
return

0 commit comments

Comments
 (0)