本帖最后由 疾风怪盗 于 2020-9-15 16:26 编辑
参考一下# coding=utf-8
import threading
from time import ctime, sleep
def music(func):
print("I was listening to %s. %s" % (func, ctime()))
sleep(1)
def move(func):
print("I was at the %s! %s" % (func, ctime()))
sleep(5)
if __name__ == '__main__':
threads = []
for i in range(0, 6):
t1 = threading.Thread(target=music, args=(u'爱情买卖',))
threads.append(t1)
for j in range(0, 4):
t2 = threading.Thread(target=move, args=(u'阿凡达',))
threads.append(t2)
for t in threads:
t.setDaemon(True)
t.start()
print("all over %s" % ctime())
|