python - Exception gevent.hub.LoopExit: LoopExit('This operation would block forever',) -


i getting error when running flask app websockets. have tried follow guide - http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent

i have flask app provides gui interface network sniffer. sniffer inside thread shown below : ( l thread sniffer; isrunning boolean check if thread running)

try:     if l.isrunning == false:  # if thread has been shut down         l.isrunning = true  # change true, loop again         running = true         l.start()  # starts forever loop / declared top 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 test.html page 

the sniffer runs fine without socketio , able sniff network while traversing gui.however, when included socketio in code, first see socketio working in index page , able receive messages server page. traverse fine other static paages in gui ;however, activating threaded network sniffer leave browser hangup. exception gevent.hub.loopexit: loopexit('this operation block forever',) error , when rerun program, console address in use. seems me may not closing sockets correctly happening. think operation blocking based error. code in python flask app shown below

def background_thread():     """example of how send server generated events clients."""     count = 0     while true:         time.sleep(10)         count += 1         socketio.emit('my response',{'data': 'server generated event', 'count': count},namespace='/test') if socketflag 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') 

here code present in index page.

<script type="text/javascript" charset="utf-8">         $(document).ready(function() {             namespace = '/test'; // change empty string use global namespace              // socket.io documentation recommends sending explicit package upon connection             // specially important when using 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 server sent data             // data displayed in "received" section of page             socket.on('my response', function (msg) {                 $('#log').append('<br>received #' + msg.count + ': ' + msg.data);             });         });   </script> 

you should avoid using time.sleep() gevent . should use gevent.sleep() instead. time.sleep() block gevent loop


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -