Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InMemoryChannelLayer improvements, test fixes #1976

Merged
merged 8 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
use create_task instead of ensure_future
  • Loading branch information
devkral committed Jul 22, 2024
commit 981fdd4c1a38af01eb7eb7aa867b798c0aa4c385
7 changes: 3 additions & 4 deletions channels/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ def __init__(
group_expiry=86400,
capacity=100,
channel_capacity=None,
**kwargs
**kwargs,
):
super().__init__(
expiry=expiry,
capacity=capacity,
channel_capacity=channel_capacity,
**kwargs
**kwargs,
)
self.channels = {}
self.groups = {}
Expand Down Expand Up @@ -287,7 +287,6 @@ def _clean_expired(self):
# Group Expiration
timeout = int(time.time()) - self.group_expiry
for channels in self.groups.values():

for name, timestamp in list(channels.items()):
devkral marked this conversation as resolved.
Show resolved Hide resolved
# If join time is older than group_expiry
# end the group membership
Expand Down Expand Up @@ -349,7 +348,7 @@ async def group_send(self, group, message):
ops = []
if group in self.groups:
for channel in self.groups[group].keys():
ops.append(asyncio.ensure_future(self.send(channel, message)))
ops.append(asyncio.create_task(self.send(channel, message)))
for send_result in asyncio.as_completed(ops):
try:
await send_result
Expand Down
2 changes: 1 addition & 1 deletion tests/test_inmemorychannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def test_race_empty(channel_layer):
"""
Makes sure the race is handled gracefully.
"""
receive_task = asyncio.ensure_future(channel_layer.receive("test-channel-1"))
receive_task = asyncio.create_task(channel_layer.receive("test-channel-1"))
await asyncio.sleep(0.1)
await channel_layer.send(
"test-channel-1", {"type": "test.message", "text": "Ahoy-hoy!"}
Expand Down