摘要:
code from queue import Queue from threading import Thread # 用来表示终止的特殊对象 _sentinel = object() # A thread that produces data def producer(out_q): for i 阅读全文
posted @ 2020-11-29 21:05
anobscureretreat
阅读(168)
评论(0)
推荐(0)
摘要:
code from queue import Queue from threading import Thread class Producer(Thread): def __init__(self, q): super().__init__() self.count = 5 self.q = q 阅读全文
posted @ 2020-11-29 21:00
anobscureretreat
阅读(173)
评论(0)
推荐(0)
摘要:
code import multiprocessing from multiprocessing import Pool,Queue import time import threading import gevent from gevent import monkey monkey.patch_a 阅读全文
posted @ 2020-11-29 20:38
anobscureretreat
阅读(112)
评论(0)
推荐(0)
摘要:
python中Queue是消息队列,提供线程间通信机制,python3中重名为为queue Queue模块中的类:Queue(maxsize=0):创建一个FIFO队列,若给定最大值,队列没有空间时阻塞,否则是无限队列LifoQueue(maxsize=0):创建一个栈,maxsize含义同上Pri 阅读全文
posted @ 2020-11-29 20:29
anobscureretreat
阅读(417)
评论(0)
推荐(0)
摘要:
code import threading import time from queue import Queue def test(data,que,index): for i in data: if(i==8900): que.put(i) print(index," ",i) pass if 阅读全文
posted @ 2020-11-29 20:13
anobscureretreat
阅读(248)
评论(0)
推荐(0)
摘要:
code import multiprocessing from multiprocessing import Pool import time import threading g_num = 0 def test1(): for i in range(10): time.sleep(1) pri 阅读全文
posted @ 2020-11-29 20:00
anobscureretreat
阅读(239)
评论(0)
推荐(0)
摘要:
code import time import threading class MyCounter(threading.Thread): """自定义线程类型,继承threading.Thread类""" # 类属性 num = 1 def run(self): """重写run方法,在线程star 阅读全文
posted @ 2020-11-29 19:57
anobscureretreat
阅读(146)
评论(0)
推荐(0)
摘要:
code import gevent,time from gevent import monkey monkey.patch_all() #gevent三行放在其他所有import语句之前可以避免出现警告或者报错信息,导致程序不能正常运行 def test1(): for i in range(10 阅读全文
posted @ 2020-11-29 19:54
anobscureretreat
阅读(112)
评论(0)
推荐(0)
摘要:
code """ 守护线程:一个子线程,会随着主线程的退出直接退出 不论子线程中是否执行完成 不离不弃,死生相随 """ import threading import time def test(): while True: print(f"{threading.current_thread(). 阅读全文
posted @ 2020-11-29 11:01
anobscureretreat
阅读(366)
评论(0)
推荐(0)

浙公网安备 33010602011771号