Gevent.hub.LoopExit exception: LoopExit ("This operation will be blocked forever",)

I always get this error when starting my Flask application using Websockets. I tried to follow this guide - http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent

I have a flash application that provides a GUI interface for my network sniffer. The sniffer is inside the stream, as shown below: (l is the stream for my sniffer; isRunning is a boolean to check if the stream is running)

try:
    if l.isRunning == False:  # if the thread has been shut down
        l.isRunning = True  # change it to true, so it could loop again
        running = True
        l.start()  # starts the forever loop / declared from the top to be a global variable
        print str(running)
    else:
        running = True
        print str(running)
        l.start()
except Exception, e:
    raise e
return flask.render_template('test.html', running=running)  #goes to the test.html page

, gui. , , , , . paages, , , . Exception gevent.hub.LoopExit: LoopExit ( " ",), , , . , , . , . python flask

def background_thread():
    """Example of how to send server generated events to clients."""
    count = 0
    while True:
        time.sleep(10)
        count += 1
        socketio.emit('my response',{'data': 'Server generated event', 'count': count},namespace='/test')
if socketflag is None:
    thread = Thread(target=background_thread)
    thread.start()


@socketio.on('my event', namespace='/test')
def test_message(message):
    emit('my response', {'data': message['data']})

@socketio.on('my broadcast event', namespace='/test')
def test_message(message):
    emit('my response', {'data': message['data']}, broadcast=True)

@socketio.on('connect', namespace='/test')
def test_connect():
    emit('my response', {'data': 'Connected'})

@socketio.on('disconnect', namespace='/test')
def test_disconnect():
    print('Client disconnected')

, .

<script type="text/javascript" charset="utf-8">
        $(document).ready(function() {
            namespace = '/test'; // change to an empty string to use the global namespace

            // the socket.io documentation recommends sending an explicit package upon connection
            // this is specially important when using the global namespace
            var socket = io.connect('http://' + document.domain + ':' + location.port + namespace);
            socket.on('connect', function () {
                socket.emit('my event', {data: 'I\'m connected!'});
            });

            // event handler for server sent data
            // the data is displayed in the "Received" section of the page
            socket.on('my response', function (msg) {
                $('#log').append('<br>Received #' + msg.count + ': ' + msg.data);
            });
        });
  </script>
+2
2

, threading.

gevent:

from gevent import monkey, sleep
monkey.patch_all()
+2

time.sleep() gevent. gevent.sleep(). time.sleep() gevent

+1

Source: https://habr.com/ru/post/1652050/


All Articles