Python多线程求助,下面的子线程程序为什么会执行两遍

import threading
from time import ctime,sleep
import time

def music(func):
    for i in range(2):
        print ("Begin listening to %s. %s" %(func,ctime()))
        sleep(4)
        print("end listening %s"%ctime())

def movie(func):
    for i in range(2):
        print ("Begin watching at the %s! %s" %(func,ctime()))
        sleep(5)
        print('end watching %s'%ctime())

threads = []
t1 = threading.Thread(target=music,args=('七里香',))
threads.append(t1)
t2 = threading.Thread(target=movie,args=('阿甘正传',))
threads.append(t2)

if __name__ == '__main__':

    for t in threads:
        # t.setDaemon(True)
        t.start()
        # t.join()

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

music和movie为什么会执行两遍




#笔试题目##Python#
全部评论
楼上正解
点赞 回复 分享
发布于 2018-08-30 16:50
for i in range(2):  这不就是输出两次了
点赞 回复 分享
发布于 2018-08-30 16:43

相关推荐

评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务