Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
Using Django Channels for a progress indicator

I have a django app that carries out some calculations on the server which can take up to 30 seconds. I am trying to use django channels to create a progress indicator.

My setup is based on this tutorial: https://realpython.com/blog/python/getting-started-with-django-channels/

Everything is working as expected so far. I submit a task by web socket. This is received by my consumer, which calls other methods to complete the task, then returns the result by websocket.

However, when I try to send multiple messages from the same consumer, all the messages arrive together at the end, rather than arriving when they are sent.

Here is my consumer code:

@channel_session
def ws_receive(message):
    data = json.loads(message['text'])
    reply_channel = message.reply_channel.name

    Channel(reply_channel).send({
        "text": json.dumps({'progress': 'Starting Work'})
    })      

    # calls outside method to do work
    result = perform_calculations(data, reply_channel)

    Channel(reply_channel).send({
        "text": json.dumps({'progress': 'Finished Work','result':result })
    })  

In this example, my front end receives the 'Starting Work' and 'Finished Work' messages at the same time, even though there is a 30 second gap between them being generated.

Is there a way to get these messages to arrive in real time?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Yes there is, you could use the immediately parameter.

Channel(message.reply_channel).send({
    "text": json.dumps({'progress': 'Starting Work'})
}, immediately=True)

Also mentioned at:

How do I ensure a Django Channels message is sent immediately without delay?

about 4 years ago · Santiago Trujillo Report

0

You can to take a look to this project:

https://gitlab.com/Baurin_lg/demo_channels_rest

It's a demo to use Django Rest and Django Channels.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!