📄 xiancheng.txt
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -