码迷,mamicode.com
首页 > 编程语言 > 详细

pyhton3多线程

时间:2015-02-28 18:00:13      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

from time import ctime,sleep

def music():
for i in range(2):
print ("I was listening to music. %s" %ctime())
sleep(1)

def move():
for i in range(2):
print ("I was at the movies! %s" %ctime())
sleep(5)

if __name__ == ‘__main__‘:
music()
move()
print ("all over %s" %ctime())

 

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)

 

if __name__ == ‘__main__‘:
music("test1")
move("test2")

print ("all over %s" %ctime())

#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‘test1‘,))
threads.append(t1)
t2 = threading.Thread(target=move,args=(u‘Test2‘,))
threads.append(t2)

if __name__ == ‘__main__‘:
for t in threads:
t.setDaemon(True)
t.start()

print ("all over %s" %ctime())

第三部分线程任务处理。

pyhton3多线程

标签:

原文地址:http://www.cnblogs.com/wcLT/p/4305607.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!