
#线程
俞泰鑫
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
python 线程同步互斥方式 -- 线程event(事件))和线程锁
python 线程锁语法from threading import Locklock = Lock() #创建锁对象lock.acquire() #上锁,若lock已经上锁再调用会阻塞lock.release() #解锁with lock: #上锁(代码执行完自动解锁)示例from threading import Thread,Locka = b =0#创建锁对象lock...原创 2019-11-13 19:17:54 · 879 阅读 · 0 评论 -
python自定义线程类
python自定义线程类import threading import Thread#继承自Thread父类class Myclass(Thread): # def __init__(self,target=None,args=(),kwargs={}): super().__init__() self.target = target self.args = args ...原创 2019-11-13 17:15:51 · 930 阅读 · 4 评论 -
python 线程函数传参
python 线程函数传参from threading import Threadfrom time import sleep#含有参数的分支线程函数def fun(sec,name): print('%s线程开始执行'%name) sleep(sec) print('%s执行完毕'%name)#创建多个线程#放线程对象的容器jobs = []for i in rang...原创 2019-11-13 16:54:14 · 1248 阅读 · 0 评论 -
python threading模块创建线程和多线程
'''步骤:1. 封装线程函数2. 创建线程对象3. 启动线程4. 回收线程'''import threadingfrom time import sleepa = 1#分支线程函数def music(): #修改全局变量 global a a = 10000 print('a = ',a) for i in range(3): sleep(2) #...原创 2019-11-13 16:43:26 · 305 阅读 · 0 评论