Search code examples
pythondjangowebsocketdjango-channels

how to make django channel comsumer to send reply asynchronously


in my consumer, I write several reply_channel.send

> def ws_message(message):    
>     line = get_output()
>     message.reply_channel.send({
>         "text": line,
>     })
>     line = get_output()
>     message.reply_channel.send({
>         "text": line,
>     })    line = get_output()
>     message.reply_channel.send({
>         "text": line,
>     })

And I found that the consumer did not send these three replies until the last message.reply_channel.send is executed.

What can I do to make it send a reply immediately when each reply_channel.send is executed?

I did this because I have a program generating an output at a random interval. If I use the code above, the webpage will wait until the full result arrives and it's quite unfriendly for users.

Thanks!


Solution

  • pass immediate=True to the send argument.