这是在廖雪峰网站上的代码;
#coding:utf-8
import time, threading
def loop():
print 'thread %s is running...' % threading.current_thread().name
n = 0
while n < 10:
n = n + 1
print 'thread %s >>> %s' % (threading.current_thread().name, n)
time.sleep(0.1)
print 'thread %s ended.' % threading.current_thread().name
print 'thread %s is running...' % threading.current_thread().name
t = threading.Thread(target=loop, name='LoopThread')
t.start()
#t.join()
print 'thread %s ended.' % threading.current_thread().name
我自己也写了一个多线程的小脚本:
https://github.com/hzlRises/hzlgithub/blob/master/RankingMonitoring/monitoring.py
在我写的这个里,为什么加了join函数以后,运行比不加join要慢很多
如果join函数的意思是等待上一个线程执行完再执行下一个线程,那写多线程的意义在哪里?