Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda