2020
09-28
09-28
python 实现两个线程交替执行
我就废话不多说,直接看代码吧!importthreadingimporttimedefa():whileTrue:lockb.acquire()print('a')locka.release()time.sleep(0.5)defb():whileTrue:locka.acquire()print('b')lockb.release()time.sleep(0.5)if__name__=="__main__":locka=threading.Lock()lockb=threading.Lock()ta=threading.Thread(None,a)tb=threading.Thread(None,b)locka.acquire()...
继续阅读 >