设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 数据 创业者 手机
当前位置: 首页 > 站长学院 > MySql教程 > 正文

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

发布时间:2022-04-01 10:49 所属栏目:115 来源:互联网
导读:使用Python多线程实现极速赛车平台搭建: 1,我所使用到的python版本:企 娥:217 1793 408 2,下面编写具体的极速赛车平台搭建实现过程 import threading import time import Queue #首先生成一个队列 q =Queue.Queue() #生产者 def producer(name): l=threa
         使用Python多线程实现极速赛车平台搭建:

      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()

(编辑:ASP站长网)

    网友评论
    推荐文章
      热点阅读