_thread模块是python 中多线程操作的一种模块方式,主要的原理是派生出多线程,然后给线程加锁,当线程结束的 时候取消锁,然后执行主程序
start_new_thred(function,args,kwargs=none) | 派生一个新的线程,使用给定的argvs,和可选的kwargs 来执行function |
allocate_lock() | 分配locktype 锁对象 |
exit() | 给线程退去指令 |
locktype 锁对象的方法 | |
qcquire(wait=none) | 尝试获取锁对象 |
Locked() | 如果获取了锁对象则返回true ,否则false |
release() | 释放锁 |
程序的代码
#!/usr/bin/python
from time import sleep,ctime
import _thread
loops=[4,2] #定义任务的时间长短
def loop(nloop,nsec,lock): # nloop 任务的名称 nesc 任务执行的时间 lock 锁
print ('loop',nloop,'start at:', ctime()) #输出任务的开始的时间
sleep(nsec) # 任务的执行时间
print('loop',nloop, 'done at:',ctime())#输出任务的结束时间
lock.release() #释放任务的锁
def main():
print ('starting at:',ctime()) #开始执行任务的当前时间
locks=[] # 定义一个空的锁列表
nloops=range(len(loops)) #主要作用是为了下面循环区分具体的任务 for i in nloops:
lock=_thread.allocate_lock() #给任务加上锁
lock.acquire()#获取锁对象
locks.append(lock) #把具体的锁对象加到锁列表里面去
for i in nloops:#循环时间长短
_thread.start_new_thread(loop,(i, loops[i],locks[i])) #派生出两个新的线程 并传递给循环,其中loops[i]传递给 nesc ,locks[i] 传递给 lock
for i in nloops:# 循环时间长短
while locks[i].locked():#判断派生的线程有没有锁,,如果有暂停主线程,直到所有的锁都释放了才会执行主线程
pass
print ('all doneat:', ctime()) if __name__ == '__main__': #执行函数
main()
任务执行的结果
关于给任务加锁的说明 (第一个for 循环)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAmgAAAECCAIAAADFCry/AAAXdElEQVR4nO3dQZqjKhSGYZbVDwtiC7UNdtE7YFir6JkrqDXcAXegkQMe1JNoYirf+9SgmxhCjPoLMeLyuuizj+W/Pkz/SCHHoSyTslIul5eGmJ0rf2n5kM+ijhx9jkPOqWqJ+nIr5UPMIVUlQbxKr547TK2tS/T1k7K7rR8vGrOyftT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c7+N19wAAGuK/f0eAADiyB4AQDayBwCQjewBAGQjewAA2cgeAEA2sgcAkI3sAQBkI3sAANnIHgBANrIHAJCN7AEAZCN7AADZyB4AQDayBwCQjewBAGQjewAA2cgeAEA2sgcAkI3sAQBkI3sAANnIHgBANrIHAJCN7AEAZCN7AADZyB4AQDayBwCQjewBAGQjewAA2cgeAEA2sgcAkO0iez6787NheGN44T//QvYAANa1/7zn09/dePlPPO8BAKzsefZ8fefGvQ95zQ0AsLp3//k0ez565Wd3PuXnPQCABPyuAQAgG9kDAMhG9gAAspE9AIBsZA8AIBvZAwDIRvYAALKRPQCAbGQPACAb2QMAyEb2AACykT0AgGxkDwAgG9kDAMhG9gAAspE9AIBsZA8AIBvZAwDIRvYAALKRPQCAbGQPACAb2QMAyEb2AACykT0AgGxkDwAgG9kDAMhG9gAAspE9AIBsZA8AIBvZAwDIRvYAALKRPQCAbGQPACAb2QMAyEb2AACykT0AgGxkDwAgG9kDAMhG9gAAspE9AIBsZA8AIBvZAwDIRvYAALKRPQCAbGQPACAb2QMAyEb2AACykT0AgGxkDwAgG9kDAMhG9gAAspE9AIBsZA8AIBvZAwDIRvYAALKRPQCAbGQPACAb2QMAyEb2AACykT0AgGxkDwAgG9kDAMhG9gAAspE9AIBsZA8AIBvZAwDIRvYAALKRPQCAZP8P1Q6UMTJKK5kAAAAASUVORK5CYII=" alt="" />
关于程序的思路流程:
导入时间模块
导入 _thread 模块
定义一个任务时间长短列表
执行mian 函数
输出开始执行的时间
定义空的锁列表
第一个循环主要是获取锁对象,给任务加上锁 把具体的锁对象加到锁列表里面去
第二个循环主要的作用是派生出两个新的线程。执行,loop函数,传递参数给 loop 函数
。
判断线程有没有锁。如果有暂定主线程,没有的话 执行下面代码结束输入