python program freezes after client connects
<p>I have this python program which uses flask for video streaming( sequence of independent JPEG pictures). I know I should debug this myself first but as soon as the client connects index.html only shows a broken image icon and the computer freezes. 
I have tried -</p>

<ul>
<li>Running it on linux where it runs fine.</li>
<li>disabling or enabling threading but it has no effect.<br><br></li>
</ul>

<p><strong>edit 2</strong> : </p>

<p>It worked on Linux because it had python 2.7 installed. In python 3 it doesn't show any error but doesn't work. Tried it on four systems(both windows and linux) and it seems to be a compatibility problem because it failed on all computers with python 3 but not with python 2.How can it be made to work in python 3?</p>

<p><strong>edit 1</strong> : The freezing has been fixed by adding <code>time.sleep(1)</code> inside the loop in <code>gen()</code> but there is still no output in the browser.Recorded the network activity in chrome developer tools. Here's a screenshot - 
<a href="https://i.stack.imgur.com/xRuzC.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/xRuzC.jpg" alt="enter image description here"></a></p>

<p>Here is the code :<br><br></p>

<p>app.py(server)</p>

<pre><code>#!/usr/bin/env python
from flask import Flask, render_template, Response

# emulated camera
from camera import Camera

app = Flask(__name__)


@app.route('/')
def index():
    """Video streaming home page."""
    return render_template('index.html')


def gen(camera):
    """Video streaming generator function."""
    while True:
        frame = camera.get_frame()
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')


@app.route('/video_feed')
def video_feed():
    """Video streaming route. Put this in the src attribute of an img tag."""
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')


if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=False, threaded=False)
</code></pre>

<p>camera.py</p>

<pre><code>from time import time
class Camera(object):
    """An emulated camera implementation that streams a repeated sequence of
    files 1.jpg, 2.jpg and 3.jpg at a rate of one frame per second."""

    def __init__(self):
        self.frames = [open(f + '.jpg', 'rb').read() for f in ['1', '2', '3']]

    def get_frame(self):
        return self.frames[int(time()) % 3]
</code></pre>

<p>index.py(client)</p>

<pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Video Streaming Demonstration&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;Video Streaming Demonstration&lt;/h1&gt;
    &lt;img src="{{ url_for('video_feed') }}"&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>As I have already mentioned I can't use a debugger because the whole computer freezes immediately.python version - 3.5 and os - windows 10.<br> How can I fix it?</p>

<p>It appears that you might want to double check the routes to the image files from app.py, i.e. make sure they're in the same directory or if they're in an /images directory, double check the path to the files or that they are there to begin with.</p>

<p>As a test, (git) clone Miguel's project and run it and see whether you get the same result.</p>

<p><a href="https://blog.miguelgrinberg.com/post/video-streaming-with-flask" rel="nofollow">https://blog.miguelgrinberg.com/post/video-streaming-with-flask</a></p>

python windows python-3.x flask mjpeg