除了线程同步,还需要注意的是「窗口处理」要放在主线程

#!/usr/bin/env python3
# -*- coding: utf-8 -*- import sys
import threading
from time import sleep
from queue import Queue
import cv2
import numpy as np
from functools import reduce print(sys.version) q = Queue() def run(n):
thread = threading.current_thread()
thread.setName('thread-fuck')
print('tid is: {0}'.format(thread.ident))
print('thread name is: {0}'.format(thread.getName())) for i in range(100):
img = np.random.randint(0,255,(200,300)).astype(np.uint8)
q.put(img)
sleep(0.1) q.put(0) if __name__ == '__main__':
thread = threading.Thread(target=run, args=(6,))
thread.start() while True:
try:
item = q.get(block=False)
except Exception as e:
keycode = cv2.waitKey(20)
if keycode & 0xFF == ord('q'):
break
continue if type(item) == int:
break if type(item) == type(0):
break
cv2.imshow('fuck', item) thread.join() cv2.waitKey(0)
cv2.destroyAllWindows()
print('done!')

最新文章

  1. linux c 笔记-3 c语言基础知识
  2. Windows Server 2003 服务器备份和恢复技巧
  3. fabric批量操作远程操作主机的练习
  4. 【SDOI2010题集整合】BZOJ1922~1927&1941&1951&1952&1972&1974&1975
  5. ahjesus C# Flags 位域略说
  6. hdu-5586 Sum(dp)
  7. Fedora 20下安装官方JDK替换OpenJDK并配置环境变量
  8. ReactNative 踩坑小计
  9. cannot be resolved to a type in same package 问题解决
  10. 谈谈文件增量同步算法:RSYNC和CDC
  11. DLR、ASTER GDEM、SRTM3、GMTED2010等5种全球高程数据对比
  12. JS分两种数据类型,你都知道吗?
  13. Python-快速排序
  14. 基于Vue.js的大型报告页项目实现过程及问题总结(一)
  15. html5的八大特性
  16. ●BZOJ 3309 DZY Loves Math
  17. 不可错过的Node.js框架
  18. 简简单单的Vue3(插件开发,路由系统,状态管理)
  19. 【vue】vue +element 搭建项目,使用el-date-picker组件遇到的坑
  20. 1分钟看懂log4j 配置自己想要的日志信息

热门文章

  1. Clip Studio Paint EX 1.10.6安装破解教程
  2. (opencv09)cv2.getStructuringElement()构造卷积核
  3. 过渡——transition
  4. [源码解析] 机器学习参数服务器ps-lite 之(3) ----- 代理人Customer
  5. JavaEE在线就业班2.0-(1)-《博学谷》
  6. MarkDown语法(Typora软件为例)
  7. 什么是RSA
  8. Java集合框架和数组的排序(转载)
  9. Mybatis源码解析2—— 实例搭建
  10. Python 可变数据类型与不可变数据类型