Python协程

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

def thread1():  
    for x in range(4):  
        yield x  
          
  
def thread2():  
    for x in range(4,8):  
        yield x  
          
  
threads=[]  
threads.append(thread1())  
threads.append(thread2())  
  
  
def run(threads):  
    for t in threads:  
        try:  
            print t.next()  
        except StopIteration:  
            pass  
        else:  
            threads.append(t)   
  
run(threads)