参考博客: www.cnblogs.com/yuanchenqi/articles/5733873.html

并发:一段时间内做一些事情

并行:同时做多件事情

线程是操作系统能够进行运算调度的基本单位,一个线程就是一个指令集

IO 密集型任务或函数  计算密集型任务函数

t1 = threading.Thread( target=foo, args=( , ))

t1.start()

# _author: lily
# _date: 2019/1/29

import threading
import time


class MyThread(threading.Thread):
    def __init__(self, num):
        threading.Thread.__init__(self)
        self.num = num

    def run(self):   # 定义每个线程要运行的函数
        print('running on number %s' % self.num)
        time.sleep(3)


if __name__ == '__main__':
    t1 = MyThread(1)
    t2 = MyThread(2)
    t1.start()
    t2.start()
View Code

相关文章: