xq8995209 发表于 2018-8-16 11:51:07

python线程编程

#!/usr/bin/python  
#_*_coding:utf-8_*_
  

  
import threading
  
import time
  

  
def Producer():
  

  
    print 'chef : 等人来买包子。。。'
  
    event.wait()
  
    event.clear()
  

  
    print 'sb is coning for baozi...'
  

  
    print 'chef : making a baozi for sb...'
  
    time.sleep(3)
  

  
    print 'chef : 你的包子好了'
  
    event.set()
  

  
def Consumer():
  

  
    print 'maxi : 去买包子'
  
    event.set()
  

  
    time.sleep(1)
  
    print 'maxi : waiting for baozi tobe readly'
  
    event.wait()
  

  
    print '哎呀,真好吃'
  

  
event = threading.Event()
  

  
p = threading.Thread(target=Producer)
  
c = threading.Thread(target=Consumer)
  

  
p.start()
  
c.start()


页: [1]
查看完整版本: python线程编程