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

163
Views
Flask returning a generator and handling it in JavaScript

I am trying to figure out how to send a constant stream of data in Flask and then read it in JavaScript.

This example is very basic because I am just trying to get it working.

Flask route:

@app.route("/gen", methods=["GET"])
def gen():
    def make():
        while True:
            yield "Hello"
            time.sleep(1)
    return Response(make())

JavaScript:

<script>
    const url = 'http://10.0.1.11:8001/gen';

    fetch(url)
        .then(function (response) {
            return response;
        })
        .then(function (data) {

            console.log(data)

        })
</script>

This prints to the console log only one time and I do not see the message "Hello". What I would like to see is "Hello" printed every second. My end goal is to send json from my generator and parse it in my html document.

Thanks, Chris

about 4 years ago · Juan Pablo Isaza
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!