zoukankan      html  css  js  c++  java
  • 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()
    三、
     
  • 相关阅读:
    数据增强
    变态跳台阶
    跳台阶
    数据分析--简单回测框架开发
    数据分析--羊驼交易法则(选股)
    数据分析--动量策略vs反转策略(选股)
    数据分析--PEG策略(选股)
    数据分析--布林带策略(择时)
    数据分析--均值回归策略(选股)
    数据分析--单因子选股策略、多因子选股策略(选股)
  • 原文地址:https://www.cnblogs.com/niaocaizhou/p/11064948.html
Copyright © 2011-2022 走看看