Reputation: 1993
Is there a way to stop execution and wait for input again on a socketio submittion?
For instance with the following code, on submit, the method self.check_input() validates information. If this were to show up with invalid data, I want to stop the chain of execution and keep the socket open to wait for the next 'on_submit'. currently it just keeps on rolling along with exceptions because the data was invalid...
How can this be accomplished?
from socketio.namespace import BaseNamespace
app = Flask(__name__)
app.debug = True
app.config.from_object(settings)
@app.route('/socket.io/<path:remaining>')
def iocg(remaining):
socketio_manage(request.environ, {'/testclass': TestClass}, request)
return 'done'
class TestClass(BaseNamespace):
def on_submit(self, data):
self.data = data
self.check_input()
self.r_server = Redis('localhost')
self.cgc = coregrapherconf
self.scg = supportcoregrapher
self.run_stuff()
Upvotes: 0
Views: 379
Reputation: 42758
The socket is kept open, until you close it from the client side. You have to send some status message back, so that the browser knows, that something goes wrong:
class TestClass(BaseNamespace):
def on_submit(self, data):
self.data = data
if not self.check_input():
return "invalid data"
self.r_server = Redis('localhost')
self.cgc = coregrapherconf
self.scg = supportcoregrapher
self.run_stuff()
return "everything's ok"
Upvotes: 1