标题:我用opencv+flask连接了网络摄像头,有用flask_scoket上传温度等数据,但跑不 ...
取消只看楼主
swordrm
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-6-10
 问题点数:0 回复次数:0 
我用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)

我知道有很多错误
搜索更多相关主题的帖子: opencv import thread time app 
2019-06-10 20:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-495205-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.217979 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved