# python 多线程
# /usr/sbin/py/python
# -*-coding:utf8-*-
import threading,time
def hi(name):
print("hi %s"%name)
time.sleep(2)
print("ending>>>")
def hello(name):
print("hello %s"%name)
time.sleep(10)
print("ending>>>")
class MyThread(threading.Thread):
def __init__(self,name):
threading.Thread.__init__(self)
self.name = name
def run(self):
time.sleep(2)
print("hello %s"%self.name)
if __name__=="__main__":
t1 = threading.Thread(target=hi,args=("jake",))
t1.start()
t2 = threading.Thread(target=hello, args=("tom",))
t2.setDaemon(True) # 守护线程和主线程同时退出 如果主线程执行完毕,守护线程中断
t3 = MyThread("lufei")
t2.start()
t3.start()
t1.join() # 等待,将线程加入到主线程中执行
print("main method ending")
python 29 多线程 基础
最新推荐文章于 2024-12-22 05:00:00 发布
1113

被折叠的 条评论
为什么被折叠?



