[英]Flask RuntimeError: working outside of application context
I want to run my Flask app with websocket. 我想使用websocket运行我的Flask应用。 Everything seems to be ok as long as I am starting my joiner class (running as thread) and then want to register a call back funktion.
只要启动我的连接器类(以线程身份运行),然后想要注册回叫功能,一切似乎就可以了。 This works ok with flask development server.
这可以与flask开发服务器一起使用。 As I am not very good in Englisch I have problems to understand the context issues with Flask.
由于我不太擅长英语,所以在理解Flask的上下文问题时遇到了问题。 Any help would be very much appreciated
任何帮助将不胜感激
@socketio.on('change_R8', namespace='/fl')
def change_Relay8(R8_stat):
if R8_stat == 'on':
#print("Relay 8 on")
ui.set_relay(8,1,0)
elif R8_stat == 'off':
#print("Relay 8 off")
ui.set_relay(8,0,0)
# Listen for SocketIO event that will change analog output
@socketio.on('change_ao', namespace='/fl')
def change_ao(ao_value):
#print("setze ao auf: ", ao_value)
ui.set_ao(ao_value)
#- call back function from UniPi_joiner_class----------------------------
def unipi_change(event, data):
#print("Webserver in: ",event,data)
emit_to_all_clients(event, data)
# main program ----------------------------------------------------------
if __name__ == "__main__":
log.text("Flask Web-Server gestartet")
print("Flask Web-Server gestartet")
joiner = unipi_joiner("10.0.0.52",0)
joiner.on_unipi_change(unipi_change)
socketio.run(app, host='127.0.0.1', use_reloader=False, debug=False)
log.text("Flask Web-Server beendet")
The joiner function delivers data from sensors in the format event, data(json) which I emit to my website with broadcast. Joiner函数以事件的形式从传感器传递数据,即data(json),该事件通过广播发送到我的网站。 The data comes from 2 different sources (time dependend) and are joined together in the joiner function using queues.
数据来自2个不同的来源(时间相关),并使用队列在joiner函数中结合在一起。 This works ok with Flask development server.
Flask开发服务器可以正常工作。 When I use eventlet then joiner.on_unipi_change(unipi_change) does not work and shows context error.
当我使用eventlet时,joiner.on_unipi_change(unipi_change)不起作用,并显示上下文错误。 I tested the server with data from within flask and it worked.
我用flask中的数据测试了服务器,它正常工作。
Question: would it be possible to deliver the sensor data through websocket to my Flask server and then from flask server to my web-site. 问题:是否可以通过websocket将传感器数据传递到我的Flask服务器,然后再从flask服务器传递到我的网站。 This would be very interesting as I would have different Raspi 3 collecting data and sending it to my web server.
这将非常有趣,因为我将使用不同的Raspi 3收集数据并将其发送到我的Web服务器。
Regarding complete stack trace I need some guidelines (sorry Flask beginner) 关于完整的堆栈跟踪,我需要一些指导(对不起的Flask初学者)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.