python 之初识线程

xiaoxiao2021-02-28  61

# !/usr/bin/python # -*- coding:utf-8 -*- # ++++++++++++++++++++ # author: FMspider # time: 2018-5-3 8:08 # function: 初识线程 import time import threading def music(func): for i in range(2): print("Begin listening to %s. %s" %(func, time.ctime())) time.sleep(2) print("end listening %s" %time.ctime()) def move(func): for i in range(2): print("Begin listening to %s. %s" %(func, time.ctime())) time.sleep(3) print("end listening %s" % time.ctime()) threads = [] t1 = threading.Thread(target=music, args=('双截棍',)) threads.append(t1) t2 = threading.Thread(target=move, args=('人在囧途',)) threads.append(t2) if __name__ == '__main__': for t in threads: t.start() print("all over %s" %time.ctime())
转载请注明原文地址: https://www.6miu.com/read-2631176.html

最新回复(0)