当前第2页 返回上一页
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | from threading import Thread
from queue import Queue
class WorkerThread(Thread):
def __init__(self,*args,**kwargs):
Thread.__init__(self,*args,**kwargs)
self.input_queue=Queue()
def send(self,item):
self.input_queue.put(item)
def close(self):
self.input_queue.put(None)
self.input_queue.join()
def run(self):
while True:
item=self.input_queue.get()
if item is None:
break
#实际开发中,此处应该使用有用的工作代替
print (item)
self.input_queue.task_done()
#完成,指示收到和返回哨兵
self.input_queue.task_done()
return
if __name__== "__main__" :
w=WorkerThread()
w.start()
w.send( "php" )
w.send( "中" )
w.send( "文" )
w.send( "网" )
w.close()
|
运行结果:
相关推荐:
全面解析python线程优先级队列(queue)原理
Python中使用Queue和Condition进行线程同步的方法
以上就是Python线程下queue(队列)模块的用法(附实例)的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
Python软件版本的下载方式
Python实现找出序列中出现次数最多的元素
如何使用不同分隔符切分字符串
pandas技巧之 详解dataframe中的apply与applymap方法
分享Python snownlp的实例教程
Python爬虫框架scrapy的使用教程
Python:中input()与raw_input()的详解
Python的time和datetime模块详细介绍
linux自带Python吗
pandas技巧之 dataframe中的排序与汇总方法
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python线程下queue(队列)模块的用法(附实例)