当前第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继承是什么意思
Python中的继承是什么
如何用Python画一只兔子——turtle库circle()画圆函数的详细用法介绍
apache怎么支持Python
Python中print什么意思
Python spyder界面无法打开的解决方法
Python实现破解猜数游戏实例详解
Python 操作 excel 系列之:数据清洗
Python中divmod函数的用法
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python线程下queue(队列)模块的用法(附实例)