[root@localhost /]# cat threadzlg.py
#!/bin/python
import threading
import time
class mythread(threading.Thread):
    def __init__(self,name,tim):
        threading.Thread.__init__(self)
        self.name=name
        self.tim=tim
        self.lock=threading.Lock()
    def run(self):
        self.lock.acquire()
        printthreadname(self.name,self.tim)
        self.lock.release()
def printthreadname(threadname,threadtime):
    for n in range(5):    
        time.sleep(threadtime)
        print (threadname,time.ctime(time.time()))
threadA=mythread('threadA',2)
threadB=mythread('threadB',2)
threadA.start()
threadB.start()
[root@localhost /]#

10-04 15:40
查看更多