ITPub博客

首页 > 数据库 > MySQL > 使用Python多线程实现极速赛车平台搭建

使用Python多线程实现极速赛车平台搭建

原创 MySQL 作者:将来幸福 时间:2018-07-02 10:41:26 0 删除 编辑

1,我所使用到的python版本:企 娥:217 1793 408

2,下面编写具体的极速赛车平台搭建实现过程

import threading
import time 
import Queue

#首先生成一个队列
q =Queue.Queue()

#生产者
def producer(name):
l=threading.Rlock()
for i in range(40):
l.acquire()
q.put(i)
l.release()
print "this is thead name is %s ,produce num is %s" %(name,i)
time.sleep(2)

#消费者
def consumer(name):
count =0
while count <=20:
resulte =q.get()
print 'the thread name is %s and the consume num is %s' %(name,result)
time.sleep(4)

#测试
for i in range(10):
p = threading.Thread(target=producer,args=('xxxx',))
p.start()

 c =threading.Thread(target=consumer,args=('yyyy',))
        c.start()

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31544343/viewspace-2157180/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2018-06-30

  • 博文量
    2
  • 访问量
    591