温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-08-10 23:38:25 来源:ITPUB博客 阅读:250 作者:将来幸福 栏目:MySQL数据库

1,我所使用到的python版本:企 娥:217 1793 408
使用Python多线程实现极速赛车平台搭建

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()
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI