python学习笔记(九)线程

# coding=utf-8
from time import sleep, ctime
import threading


def function1(name):
    while 1:
        print(name)
        sleep(1)


def function2(name):
    while 1:
        print(name)
        sleep(1)


# 创建线程
thr1 = threading.Thread(target=function1, args=('爱情买卖.mp3',))
thr2 = threading.Thread(target=function2, args=('阿凡达.mp4',))

if __name__ == '__main__':
    # 启动线程
    thr1.start()
    thr2.start()
    thr1.join()
    thr2.join()

# 主线程
print('end:%s' % ctime())

 

你可能感兴趣的:(python学习笔记(九)线程)