我用opencv+flask连接了网络摄像头,有用flask_scoket上传温度等数据,但跑不起来,要写线程吗?

qq_44251911 2019-06-10 09:00:44
我用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)

...全文
108 回复 打赏 收藏 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

5,657

社区成员

发帖
与我相关
我的任务
社区描述
Web开发应用服务器相关讨论专区
社区管理员
  • 应用服务器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧