小编Pau*_*les的帖子

gevent.hub.LoopExit异常:LoopExit('此操作将永远阻止',)

使用Websockets运行Flask应用程序时,总是出现此错误。我尝试遵循此指南-http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent

我有一个flask应用程序,为我的网络嗅探器提供GUI界面。嗅探器位于线程内,如下所示:(l是我的嗅探器线程; isRunning是一个布尔值,用于检查线程是否已在运行)

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
Run Code Online (Sandbox Code Playgroud)

嗅探器在没有socketio的情况下运行良好,我可以在遍历gui的同时嗅探网络。但是,当我在代码中包含socketio时,我首先看到socketio在索引页面中正常工作,并且能够接收来自服务器到页面。我还可以遍历GUI中的其他静态方法;但是,激活线程网络嗅探器会使浏览器挂断。我总是收到异常gevent.hub.LoopExit:LoopExit('此操作将永远阻止',)错误,当我重新运行程序时,控制台会说该地址已被使用。在我看来,这种情况可能无法正确关闭我的套接字。我还认为某些操作正在阻止该错误。我的python flask应用程序中的代码如下所示

def background_thread():
    """Example of how to send …
Run Code Online (Sandbox Code Playgroud)

python multithreading flask socket.io flask-socketio

4
推荐指数
2
解决办法
3856
查看次数