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:
l.isRunning = True
running = True
l.start()
print str(running)
else:
running = True
print str(running)
l.start()
except Exception, e:
raise e
return flask.render_template('test.html', running=running)
, 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';
var socket = io.connect('http://' + document.domain + ':' + location.port + namespace);
socket.on('connect', function () {
socket.emit('my event', {data: 'I\'m connected!'});
});
socket.on('my response', function (msg) {
$('#log').append('<br>Received #' + msg.count + ': ' + msg.data);
});
});
</script>