线程

import  time
from threading import Thread
#第一种方式启动线程
# def func(n):
# time.sleep(1)
# print(n)
#
# for i in range(10):
# t = Thread(target = func,args=(i,))
# t.start()
#第二种方式启动线程
class Mythread(Thread):
def __init__(self,args):
super().__init__()
self.args=args

def run(self):
time.sleep(1)
print(self.args)

t =Mythread(10)
t.start()
#进程是最小的内存分配单位
#线程是操作系统调度的最小单位
#线程被CPU执行了
#进程内至少含有一个线程
#进程中可以开启多个线程


#守护进程随着主进程代码的执行结束而结束
#守护线程会在主线程结束之后等待其他子线程的结束而结束
原文地址:https://www.cnblogs.com/liu1983/p/13619891.html