我用opencv+flask连接了网络摄像头,有用flask_scoket上传温度等数据,但跑不起来,要写线程吗?
程序代码:
from flask import Flask, render_template from flask_socketio import SocketIO,emit from threading import Lock import random,time async_mode = None app = Flask(__name__) app.config['SECRET_KEY'] = 'secret!' socketio = SocketIO(app) thread = None thread_lock = Lock() thread1_lock = Lock() @app.route('/') def index(): return render_template('test.html') @socketio.on('connect', namespace='/test_conn') def test_connect(): global thread with thread_lock: if thread is None: thread = socketio.start_background_task(target=background_thread) def background_thread(): while True: socketio.sleep(5) a = time.strftime('%M:%S', time.localtime()) t = random.randint(1, 100) socketio.emit('server_response', {'data': t,'time': a},namespace='/test_conn') if __name__ == '__main__': app.run (debug=True,threaded = True)
我知道有很多错误