# -*- coding: utf-8 -*-
"""
Created on Fri Aug 12 12:52:40 2016
@author: zhangweiguo
"""
import threading
from time import ctime,sleep
def music():
for i in range(5):
print "I was listening to music %s" %(ctime())
sleep(1)
def move():
for i in range(5):
print "I was at the movie %s" %(ctime())
sleep(1)
print 'begin:',ctime()
threads = []
t1 = threading.Thread(target=music)
threads.append(t1)
t2 = threading.Thread(target=move)
threads.append(t2)
if __name__=='__main__':
#两个线程,第一个线程先走一步
for t in threads:
t.setDaemon(True)
t.start()
t1.join()
t2.join()
#join的目的是确认子进程结束后再调用主进程
print 'end:',ctime()
1、http://www.cnblogs.com/sevenyuan/archive/2010/12/06/1898073.html/
2、http://python.jobbole.com/81546/