xiancheng.txt
来自「python源码」· 文本 代码 · 共 40 行
TXT
40 行
name:testThread.py
import threading
import time
import random
class PrintThread(threading.Thread):
"""欢您的使用
你还好吗"""
def __init__(self,threadname):
threading.Thread.__init__(self)
self.sleepTime = random.randint(1,3)
self.name = threadname
print 'Name:%s\tSleep:%d'%(threadname,self.sleepTime)
def run(self):
print "\n%s going to sleep for %s second(s)"%(self.name, self.sleepTime)
time.sleep(self.sleepTime)
print "\n",self.name, 'done sleeping'
num = 5
i = 0
threadList=[]
for i in range(i,num+1):
thread = PrintThread('Thread'+str(i))
threadList.append(thread)
print '\n Starting Threads'
for i in threadList:
i.start()
print 'All Threads Started\n'
for i in threadList:
i.join()
print 'All Threads Stop\n'
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?