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

Added custom consume many in AsyncConsumer.__call__ #2120

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

IsmoilovMuhriddin
Copy link

Idea for Issue #1119 and #1466

Main problem with why websocket.disconnect not called within daphne.server.Server.application_close_timeout (example: 10 seconds) is:

  • channels.consumer will handle messages(from daphne server and channel layer) one by one
  • if there any message taking too long(send to client, or receive), any incoming messages will be in a queue, and wait to be handled. and if daphne closes the WebSocket consumer, those messages are not closed gracefully, and websocket.disconnect method is not called.

example code to run this

import asyncio
from channels.utils import await_many_dispatch_with_priority
from channels.generic.websocket import AsyncJsonWebsocketConsumer

class CustomWebsocketConsumer(AsyncJsonWebsocketConsumer):
    # uncomment below line 
    # await_many_and_dispatch = await_many_dispatch_with_priority
    
   def send_message(self, message):
       await self.send_json(message)
       await asyncio.sleep(11)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant