Skip to content

Commit

Permalink
Fix loop scope closures
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarkovtsev committed Jun 5, 2020
1 parent aa0d4c0 commit 91af09f
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions server/athenian/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,15 @@ async def close(self):
if proto is None:
continue
transports += 1
orig_lost = proto.connection_lost
orig_eof_received = proto.eof_received

def connection_lost(exc):
def connection_lost(orig_lost, exc):
orig_lost(exc)
nonlocal transports
transports -= 1
if transports == 0:
all_is_lost.set()

def eof_received():
def eof_received(orig_eof_received):
try:
orig_eof_received()
except AttributeError:
Expand All @@ -164,8 +162,9 @@ def eof_received():
# Jeez, asyncio sucks sometimes.
pass

proto.connection_lost = connection_lost
proto.eof_received = eof_received
proto.connection_lost = functools.partial(
connection_lost, proto.connection_lost)
proto.eof_received = functools.partial(eof_received, proto.eof_received)
await session.close()
if transports > 0:
await all_is_lost.wait()
Expand Down

0 comments on commit 91af09f

Please sign in to comment.