博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
多线程02
阅读量:4678 次
发布时间:2019-06-09

本文共 961 字,大约阅读时间需要 3 分钟。

# -*- coding: utf-8 -*-#python 27#xiaodeng#线程和进程#http://www.cnblogs.com/fnng/p/3691053.html#多线程:from time import sleep,ctimeimport threadingdef move(func):    for i in range(2):        print 'Start playing:%s.%s'%(func,ctime())        sleep(5)def music(func):    for i in range(2):        print 'Start playing:%s.%s'%(func,ctime())        sleep(2)def player(name):     r=name.split('.')[1]    if r=='mp3':        music(name)    else:        if r=='mp4':            move(name)        else:            print 'error:the format is not recognized!'list=[u'爱情买卖.mp3',u'大秦帝国.mp4']threads=[]files=range(len(list))#创建线程for i in files:    t=threading.Thread(target=player,args=(list[i],))    threads.append(t)if __name__=='__main__':    #启动线程    for i in files:        threads[i].start()    #用于等待线程终止,    #作用:在子线程完成运行之前,这个子线程的父线程将一直阻塞。    for i in files:        threads[i].join()    #主线程    print 'end:%s'%(ctime())

 

转载于:https://www.cnblogs.com/dengyg200891/p/4940631.html

你可能感兴趣的文章
杭电3466————DP之01背包(对状态转移方程的更新理解)
查看>>
算法分析常用记号
查看>>
spring mvc 返回类型
查看>>
[js高手之路] html5 canvas动画教程 - 匀速运动
查看>>
11.VS2015常用快捷键大全
查看>>
js学习总结----less常用的方法
查看>>
需求分析问卷调查及反馈结果
查看>>
当深度学习遇见自动文本摘要
查看>>
心随手动,驱动短视频热潮的引擎
查看>>
Servlet深入之初始化
查看>>
python中出现IndentationError:unindent does not match any outer indentation level错误
查看>>
<mvc:annotation-driven />与<context:annotation-config/>
查看>>
【UML】概念、关联、画画(一)
查看>>
由于空间,注定的结果——第五届山东省ACM编程比赛总结
查看>>
Android复制iPhone日期和时间选择器
查看>>
Jquery Dom节点常用操作
查看>>
深入理解正则表达式
查看>>
php学习笔记-定义常量
查看>>
七周七语言:Io Day 2
查看>>
robotframework 下对于web弹出框的处理
查看>>