【问题标题】:my python3 threading prog didnt work with fifo-queue我的 python3 线程编程序不适用于 fifo-queue
【发布时间】:2013-05-05 09:20:36
【问题描述】:

这是我的代码:

import threading
import queue

qq=queue.Queue(10)
def x11grab(n):
    print('haha')
    while True:
        a='abcd'+str(n)
        n+=1
        qq.put(a)
        print('put queue:',a)

def rtpsend():
    while True:
        s=qq.get()
        head=s[:4]
        body=s[4:]
        print('head',head)
        print('body',body)

t1=threading.Thread(target=x11grab,args=(1,))
t2=threading.Thread(target=rtpsend)
t1.start
t2.start

我想 x11grab() 函数将字符串 'abcd1','abcd2'... 放入队列中,然后 rtpsend() 函数从队列中获取字符串,并显示它。这是一个演示,但它没有工作。我认为您的建议可能会有所帮助。:-)

【问题讨论】:

    标签: multithreading python-3.x queue


    【解决方案1】:

    你永远不会开始你的线程!改变

    t1.start
    t2.start
    

    t1.start()
    t2.start()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多