摘要: 协程:能够在一个线程中实现并发的效果,能够规避一些任务中的IO操作,在任务中的执行过程中,检测到IO就切换到其他任务 阅读全文
posted @ 2018-12-16 22:01 superniao 阅读(108) 评论(0) 推荐(0) 编辑
摘要: import time from concurrent.futures import ThreadPoolExecutor def func(i): time.sleep(2) print(i) return i**2 tpool = ThreadPoolExecutor(max_workers = 5) t_lst = [] for i in range(10): ... 阅读全文
posted @ 2018-12-16 17:35 superniao 阅读(98) 评论(0) 推荐(0) 编辑
摘要: 条件也可以理解为锁。也有acquire 、release、 wait、 notify方法 一个条件创建之初,默认有一个False状态,会影响wait一直处于等待状态 notify(int数据类型) 大白话就是制造几把钥匙 阅读全文
posted @ 2018-12-16 16:20 superniao 阅读(292) 评论(0) 推荐(0) 编辑
摘要: import time import random from threading import Thread,Event def conn_db(e): count = 0 while count < 3: e.wait(1) if e.is_set(): print("连接数据库成功") brea 阅读全文
posted @ 2018-12-16 15:55 superniao 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 守护进程随着主进程的代码的执行结束而结束 守护线程会在主线程结束之后等待其他子线程的结束才结束(如有其他子线程,没有其他子线程就是主线程结束守护线程随之结束) 主进程在执行玩完自己的代码后不会立即结束,而是等待子进程结束之后,回收子进程的资源 阅读全文
posted @ 2018-12-16 13:59 superniao 阅读(366) 评论(0) 推荐(0) 编辑
摘要: import time from threading import Thread def func(n): #time.sleep(1) print(n) for i in range(10): t = Thread(target=func,args=(i,)) t.start() import t 阅读全文
posted @ 2018-12-16 13:51 superniao 阅读(86) 评论(0) 推荐(0) 编辑