Git Product home page Git Product logo

Comments (10)

jkarneges avatar jkarneges commented on August 25, 2024

Hi,

Are you seeing this behavior when running in development mode with runserver? Or is this happening with a daphne deployment, and possibly you're running multiple instances?

from django-eventstream.

MartaLopesGomes avatar MartaLopesGomes commented on August 25, 2024

I'm running in development mode with runserver.

from django-eventstream.

jkarneges avatar jkarneges commented on August 25, 2024

I tried running the time example (in this repo) using the latest versions of all dependencies, including Django 3, and it seemed to work fine. Does it work for you too?

from django-eventstream.

MartaLopesGomes avatar MartaLopesGomes commented on August 25, 2024

I tried running the chat example, with Django 3 and it worked fine.

from django-eventstream.

jkarneges avatar jkarneges commented on August 25, 2024

Debugging further is difficult. The library could probably use some debug logging.

All I can suggest is to use curl to connect to the events endpoint in order to examine the raw stream. Also try to think about what is different with your app vs the chat example (use of threads, etc).

from django-eventstream.

MartaLopesGomes avatar MartaLopesGomes commented on August 25, 2024

I got the same result as before using curl.

I'm using a separate thread to call send_event(...). Do you think that can be the reason to observe this pattern? If yes, can you explain or do you know why that can be a problem?

from django-eventstream.

jkarneges avatar jkarneges commented on August 25, 2024

send_event is intended to be thread safe, and the time example calls it from a separate thread too, so it should be okay. But perhaps there is some extra complexity in your app that could be interfering. Are you sure send_event is actually getting called the number of times you expect? Are you using some kind of parallelization library that converts threads into processes?

from django-eventstream.

jkarneges avatar jkarneges commented on August 25, 2024

Can you trim your code down to a reproducible example and share it?

from django-eventstream.

MartaLopesGomes avatar MartaLopesGomes commented on August 25, 2024

I was sure that I was calling the send_event the number of times I was expecting.

I think I have the problem solved. But I'm not sure that I know exactly what was causing this issue.

The code that was calling the send_event was being initiated in the AppConfig.ready(). I don't know if this function was being initiated more than one time. Once I started calling python manage.py runserver with the option --noreload, the stream started receiving all the events as it should.

I think it is a solution for now, but I would like to understand better what was happening.
I would prefer to be able to use the runserver without the option --noreload.

Anyway, Thanks for your help!

from django-eventstream.

jkarneges avatar jkarneges commented on August 25, 2024

Glad to hear you've found a solution. I tried moving the time example's thread init to AppConfig.ready() and it still worked okay, even after modifying a file and letting it reload. An asgiref error was logged though.

Django's runserver reloading is tricky business and it wouldn't surprise me if there is some bug with it or in combination with Channels. Maybe upgrade your Daphne: django/channels#1374

from django-eventstream.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.