• Python---进阶---多线程---threading


    一、

    使用多线程去播放两个播放列表,一个是movie,一个是music

    _thread

    threading

     ------------------------------------------

    import _thread as thread
    import time
    movie_list = ["斗破.mp4", "复仇者联盟.avi", "钢铁雨.rmvb", "xxx.mp4"]
    music_list = ['周杰伦.mp3', '五月天.mp3']
    movie_format = ['mp4', 'avi']
    music_format = ['mp3']
    def play(playlist):
        for i in playlist:
            if i.split(".") in movie_format:
                print("你现在收看的是:{}".format(i))
                time.sleep(3)
            elif i.split(".")[1] in music_format:
                print("你现在收听的是:{}".format(i))
                time.sleep(2)
            else:
                print("没有能播放的格式")
    def thread_run():
        thread.start_new_thread(play, (movie_list, ))
        thread.start_new_thread(play, (music_list, ))
        while True:
            time.sleep()
       
    if __name__ == "__main__":
        thread_run()

    二、

    import threading
    import time
    movie_list = ["斗破.mp4", "复仇者联盟.avi", "钢铁雨.rmvb", "xxx.mp4"]
    music_list = ['周杰伦.mp3', '五月天.mp3']
    movie_format = ['mp4', 'avi']
    music_format = ['mp3']
    def play(playlist):
        for i in playlist:
            if i.split(".")[1] in movie_format:
                print("你现在收看的是:{}".format(i))
                time.sleep(3)
            elif i.split(".")[1] in music_format:
                print("你现在收听的是:{}".format(i))
                time.sleep(2)
            else:
                print("没有能播放的格式")
               
    def thread_run():
        threading.Thread(target=play, args=(movie_list, ))
        threading.Thread(target=play, args=(music_list, ))
       
       
       
    if __name__ == "__main__":
        thread_run()
    三、
     
  • 相关阅读:
    Could not update ICEauthority file /var/lib/gdm/.ICEauthority
    反爬虫中技术点的定义
    反爬虫一些问题
    反爬虫准备
    题解「BZOJ4621 Tc605」
    题解「ZJOI2019 语言」
    题解「清华集训2012 序列操作」
    题解「CF1174F Ehab and the Big Finale」
    题解「CF516D Drazil and Morning Exercise」
    题解「HNOI2018 寻宝游戏」
  • 原文地址:https://www.cnblogs.com/niaocaizhou/p/11064948.html
Copyright © 2020-2023  润新知