python3 之线程学习

from time import ctime, sleep
import threading


def music(func):
    for i in range(1):
        print("I was listening to %s.%s" % (func, ctime()))
        sleep(1)


def move(func):
    for i in range(2):
        print("I was watching the %s.%s" % (func, ctime()))
        sleep(5)


threads = []
t1 = threading.Thread(target=music, args=(u'爱情买卖',))
threads.append(t1)
t2 = threading.Thread(target=move, args=(u'阿凡达',))
threads.append(t2)

if __name__ == '__main__':
    for t in threads:
        t.setDaemon(True)
        t.start()

    print("all over %s" %ctime())

  

posted @ 2020-11-23 19:46  Penny悦  阅读(73)  评论(0编辑  收藏  举报