• ADADADADAD

    使用Python多线程实现极速赛车平台搭建[ mysql数据库 ]

    mysql数据库 时间:2024-12-03 12:13:35

    作者:文/会员上传

    简介:

    1,我所使用到的python版本:企 娥:217 1793 408
    2,下面编写具体的极速赛车平台搭建实现过程import threadingimport timeimport Queue#首先生成一个队列q =Queue.Queue()#生产者

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    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()
    使用Python多线程实现极速赛车平台搭建.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载
    热门标签: python线程使用