I have a Flask-SocketIO server, which initialize a GUI in a separated thread.
if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1] == 'dev':
print "Running Flask-SocketIO on dev mode"
else:
print "Running Flask-SocketIO on production mode"
print 'Running Graphical User Interface...'
thread.start_new_thread(display_react.main, ())
print 'Initializing server'
socketio.run(app, debug=False)
The GUI is basically the cefpthon3 example which use the wxPython, but instead of being a normal browser, it only shows up a specific page served by the server. At the moment i want the whole app shutdown when i close the GUI. For the effect, i've created a route on the server which (when called) will shutdown the server.
@app.route('/shutdown', methods=['GET'])
def shutdown():
server_request.shutdown()
socketio.stop()
print "Trying to close..."
return 'Server shutting down...'
And this route is called when before close the wxPython. However, this error appears before the server shutdown:
Can anyone help me solving or hiding this?
wxPython almost always has to be the main thread, which is most likely why you are seeing this error that is asserting on wxIsMainThread
. One somewhat easy workaround would be to start wxPython as the main thread / application and have it run Flask in a thread.
I think that will work better. You can ask on the wxPython Google group for other workarounds though.