Skip to content

Commit 257eada

Browse files
committed
Change try/finally on async generator cleanup
1 parent 5a5a6bf commit 257eada

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

examples/aiohttp/schema.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ class Subscription(graphene.ObjectType):
4141

4242
async def resolve_mutation_example(root, info):
4343
try:
44-
# sub_id, q = await p.subscribe_to_channel('BASE')
4544
sub_id, q = p.subscribe_to_channel('BASE')
4645
while True:
4746
payload = await q.get()
4847
yield payload
49-
except asyncio.CancelledError:
48+
finally:
5049
p.unsubscribe('BASE', sub_id)
5150

5251
async def resolve_count_seconds(root, info, up_to=5):

examples/websockets_lib/schema.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ class Subscription(graphene.ObjectType):
4141

4242
async def resolve_mutation_example(root, info):
4343
try:
44-
# sub_id, q = await p.subscribe_to_channel('BASE')
4544
sub_id, q = p.subscribe_to_channel('BASE')
4645
while True:
4746
payload = await q.get()
4847
yield payload
49-
except asyncio.CancelledError:
48+
finally:
5049
p.unsubscribe('BASE', sub_id)
5150

5251
async def resolve_count_seconds(root, info, up_to=5):

0 commit comments

Comments
 (0)