超级播放器

#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

最新文章

  1. DDD设计中的Unitwork与DomainEvent如何相容?
  2. javascript “||”、“&&”的灵活运用
  3. PHP面向对象中常用的关键字和魔术方法
  4. mysql_fetch_row()与mysql_fetch_array()的使用介绍
  5. find 日常使用
  6. hibernate_validator_01
  7. FileAccess枚举
  8. HTML8表单验证
  9. C#使用Xamarin开发可移植移动应用(5.进阶篇显示弹出窗口与通讯中心)附源码
  10. kappa系数在评测中的应用
  11. Windows Cluster 添加新节点--验证报错
  12. 阿里云HBase携X-Pack再进化,重新赋能轻量级大数据平台
  13. KMP 求最小循环节
  14. eclipse maven引入第三方jar包后如何下载源代码(sources)
  15. spring boot 邮件发送(带附件)
  16. php--------对象(object) 与 数组(array) 的转换
  17. Ceph块存储介绍
  18. Unity鼠标点击Collider
  19. 3dContactPointAnnotationTool开发日志(二三)
  20. java创建web服务

热门文章

  1. #ifdef #endif #if #endif
  2. 第1章 SpringBoot 简介
  3. File类 文件过滤器
  4. hdu5289(2015多校1)--Assignment(单调队列)
  5. SPOJ VLATTICE Visible Lattice Points (莫比乌斯反演基础题)
  6. 【健康生活】Google、百度之间的选择
  7. Spark 学习笔记:(四)MLlib基础
  8. Swift开发教程--怎样播放图片动画
  9. liberOJ #6173. Samjia 和矩阵 hash+后缀数组
  10. Space for commit to queue couldn't be acquired