超级播放器

#coding:utf-8
import threading
from time import sleep,ctime #超级播放器
def super_player(file,time):
for i in range(2):
print('Start playing: %s! %s' %(file,ctime()))
sleep(time) list = {'爱情买卖.mp3':3,'阿凡达.mp4':5,'我和你.mp3':2} #创建线程数组
threads = []
files = range(len(list)) for file,time in list.items():
t = threading.Thread(target=super_player,args=(file,time))
threads.append(t) if __name__ == "__main__":
#启动线程
for i in files:
threads[i].start() #守护线程
for i in files:
threads[i].join() print('all end: %s' %ctime())
首先创建字典 list ,用于定义要播放的文件及时长(秒),通过字典的 items()方法来循环的取 file

和 time,取到的这两个值用于创建线程。

接着创建 super_player()函数,用于接收 file 和 time,用于确定要播放的文件及时长。
最后是线程启动运行。运行结果:

Start playing: 爱情买卖.mp3! Thu Oct 18 10:06:57 2018
Start playing: 阿凡达.mp4! Thu Oct 18 10:06:57 2018
Start playing: 我和你.mp3! Thu Oct 18 10:06:57 2018
Start playing: 我和你.mp3! Thu Oct 18 10:06:59 2018
Start playing: 爱情买卖.mp3! Thu Oct 18 10:07:00 2018
Start playing: 阿凡达.mp4! Thu Oct 18 10:07:02 2018
all end: Thu Oct 18 10:07:07 2018

多线程-threading模块3的更多相关文章

  1. 再看python多线程------threading模块

    现在把关于多线程的能想到的需要注意的点记录一下: 关于threading模块: 1.关于 传参问题 如果调用的子线程函数需要传参,要在参数后面加一个“,”否则会抛参数异常的错误. 如下: for i ...

  2. 多线程threading模块

    python的多线程编程 简介 多线程编程技术可以实现代码并行性,优化处理能力,同时功能的更小划分可以使代码的可重用性更好.Python中threading和Queue模块可以用来实现多线程编程. 详 ...

  3. Python:多线程threading模块

    目录 Thread对象 Lock对象 local对象 Thread对象: 多任务可以由多进程完成,也可以由一个进程内的多线程完成.进程是由至少1个线程组成的. threading模块在较低级的模块 _ ...

  4. python编程中的并发------多线程threading模块

    任务例子:喝水.吃饭动作需要耗时1S 单任务:(耗时20s) for i in range(10): print('a正在喝水') time.sleep(1) print('a正在吃饭') time. ...

  5. 多线程-threading模块

    #coding:utf-8 import threading from time import sleep,ctime #音乐播放器 def music(func): for i in range(2 ...

  6. Python_多线程threading模块

    python 在执行的时候会淡定的在CPU上只允许一个线程运行,故Python在多核CPU的情况下也只能发挥出单核的功能,其中的原因:gil锁 gil 锁 (全局解释器锁):每个线程在执行时都需要先获 ...

  7. Python(多线程threading模块)

    day27 参考:http://www.cnblogs.com/yuanchenqi/articles/5733873.html CPU像一本书,你不阅读的时候,你室友马上阅读,你准备阅读的时候,你室 ...

  8. 多线程-threading模块2

    从上面例子中发现线程的创建是颇为麻烦的,每创建一个线程都需要创建一个 t(t1.t2....),如果创建的线程较多时这样极其不方便.下面对通过例子进行改进:   #coding:utf-8 impor ...

  9. Python:使用threading模块实现多线程编程

    转:http://blog.csdn.net/bravezhe/article/details/8585437 Python:使用threading模块实现多线程编程一[综述] Python这门解释性 ...

随机推荐

  1. 转: 工欲善其事,必先利其器系列--Netbeans之远程开发

    转自: http://www.cnblogs.com/zuoca/archive/2012/07/09/Remote_Development_With_Netbeans_origin.html 工欲善 ...

  2. [Tools] Convert SVG to a PDF in Node with PDFKit and SVG.js

    Given a epxress application and an svg template, we want to draw some text, date onto it and convert ...

  3. 生活娱乐 WIFI机器人(某机器发烧友自己动手做一台)

    某机器发烧友自己动手做一台WIFI机器人,以下是这位发烧友的自述!让我们一起来分享他的劳动成果-- 在经历了十多天的疯狂淘宝.组装.调试.拆卸.再组装.再调试的过程后,俺的Wifi Robot终于于2 ...

  4. 翻翻git之---"有趣效果"的自己定义View EasyArcLoading

    转载请注明出处:王亟亟的大牛之路 早上写了一个关于MD的文章,下午给编译器调了个色,感觉要上天了.所以为了试颜色就出了这篇文章,让大家一起瞎一下 好了废话不说.这一片给大家介绍一个当做Dialog作用 ...

  5. IE8.0登录Oracle EBS后报Oracle error 1403错

    IE8.0登录Oracle EBS后报错,登录页面打开没有问题.只是输入username和password然后登录,遇到下面错误: <PRE>Oracle error 1403: java ...

  6. EF使用自定义字符串连接数据库

    edmx的构造函数: public TestCheckUpdatesEntities(): base(Config.DataBaseConnectionString(), "TestChec ...

  7. CPU维修技术

    中央处理单元(Central Process Unit)简称CPU,是电脑的核心部件,负责处理和运算电脑内部所有数据.因其在电脑中的地位相当重要,所以一旦发生故障就会造成很严重的后果. [技术66]开 ...

  8. Codeforces 558C Amr and Chemistry

    题意: n个数.每次能够选一个数 让其 *=2 或者 /=2 问至少操作多少次使得全部数相等. 思路: 对于每一个数,计算出这个数能够变成哪些数,以及变成那个数的最小步数,用两个数组保存 cnt[i] ...

  9. Arrays.asList基本用法

    目录 说明 基本用法 陷阱 改观 说明 asList 是 java.util.Arrays 类的一个方法 public static <T> List<T> asList(T. ...

  10. Comparable 和 Comparator的理解

    对Comparable 的解释 Comparable是一个排序接口 此接口给实现类提供了一个排序的方法,此接口有且只有一个方法 public int compareTo(T o); compareTo ...