有没有办法在socketio提交时停止执行并再次等待输入?
例如,使用以下代码,在提交时,方法self.check_input()验证信息。如果这是为了显示无效数据,我想停止执行链并保持套接字打开以等待下一个'on_submit'。目前它只是继续滚动,因为数据无效......
如何实现这一目标?
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()
答案 0 :(得分:1)
套接字保持打开状态,直到您从客户端关闭它。您必须发回一些状态消息,以便浏览器知道出现了问题:
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"