多线程

http://www.cnblogs.com/fnng/p/3670789.html


#coding=utf-8

import threading

from time import ctime,sleep

def music(func):

for i in range(2):

print "I was listening to %s. %s" %(func,ctime())

sleep(1)

def move(func):

for i in range(2):

print "I was at the %s! %s" %(func,ctime())

sleep(5)

threads = []

t1 = threading.Thread(target=music,args=(u'爱情买卖',))

threads.append(t1)

t2 = threading.Thread(target=move,args=(u'阿凡达',))

threads.append(t2)

if __name__ == '__main__':

for t in threads:

t.setDaemon(True)

t.start()

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 多线程模块 threading 创建多线程的两种方式:import threadingimport time 创建...
    钱塘阅读 3,003评论 0 3
  • 概述 多线程给我们带来的好处是可以并发的执行多个任务,特别是对于I/O密集型的业务,使用多线程,可以带来成倍的性能...
    SimonChen阅读 13,159评论 0 5
  • 我们前面提到了进程是由若干线程组成的,一个进程至少有一个线程。多线程优点: 在一个进程中的多线程和主线程分享相同的...
    第八共同体阅读 3,480评论 0 0
  • 本文是笔者学习廖雪峰Python3教程的笔记,在此感谢廖老师的教程让我们这些初学者能够一步一步的进行下去.如果读者...
    相关函数阅读 10,860评论 1 8
  • http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958...
    喵在野阅读 9,070评论 0 1

友情链接更多精彩内容