Skip to content

Commit

Permalink
First try at supporting python 3.11, by creating tasks explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
nmpsilva committed Feb 23, 2023
1 parent 80f650a commit 73a9cab
Show file tree
Hide file tree
Showing 6 changed files with 1,401 additions and 1,625 deletions.
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
3.11
3.10.1
3.9.9
3.8.12
11 changes: 6 additions & 5 deletions channels_graphql_ws/graphql_ws_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ async def disconnect(self, code):

# Unsubscribe from the Channels groups.
waitlist += [
self._channel_layer.group_discard(group, self.channel_name)
asyncio.create_task(self._channel_layer.group_discard(group, self.channel_name))
for group in self._sids_by_group
]

Expand All @@ -277,7 +277,7 @@ async def disconnect(self, code):
waitlist += [self._keepalive_task]

if waitlist:
await asyncio.wait(waitlist)
await asyncio.wait([asyncio.create_task(f) if asyncio.iscoroutine(f) else f for f in waitlist])

self._subscriptions.clear()
self._sids_by_group.clear()
Expand Down Expand Up @@ -456,7 +456,7 @@ async def unsubscribe(self, message):
# unsubscription.
await asyncio.wait(
[
self.receive_json({"type": "stop", "id": sid})
asyncio.create_task(self.receive_json({"type": "stop", "id": sid}))
for sid in self._sids_by_group[group]
]
)
Expand Down Expand Up @@ -764,7 +764,7 @@ async def notifier():
notifier_task=notifier_task,
)

await asyncio.wait(waitlist)
await asyncio.wait([asyncio.create_task(f) if asyncio.iscoroutine(f) else f for f in waitlist])

return stream

Expand Down Expand Up @@ -811,7 +811,8 @@ async def _on_gql_stop(self, operation_id):
waitlist.append(
self._channel_layer.group_discard(group, self.channel_name)
)
await asyncio.wait(waitlist)

await asyncio.wait([asyncio.create_task(f) if asyncio.iscoroutine(f) else f for f in waitlist])

# Call the subscription class `unsubscribed` handler in a worker
# thread, cause it may invoke long-running synchronous tasks.
Expand Down
Loading

0 comments on commit 73a9cab

Please # to comment.