day 34 线程队列 线程池 协程 Greenlet \Gevent 模块

1 线程的其他方法

threading.current_thread().getName()    查询当前线程对象的名字

threading.current_thread().ident             查询当前进程对象的ID

threading.enumerate()                            目前正在活动中的线程

threading.active_count()                         目前有几条活动中的线程

2 线程队列 (数据安全)

q = queue.Queue()                先进先出 fifo first in first out

q = queue.Lifo Queue            先进后出,类似于栈

q = queue.PriorityQueue()     优先级队列

(Put的数据是一个元组,元组的第一个参数是优先级数字,数字越小优先级越高,

越先被get到被取出来,第二个参数是put进去的值,如果说优先级相同,

那么值别忘了应该是相同的数据类型,字典不行)

3 线程池与进程池

from concurrent.futures import ThreadPoolExecutor , ProcessPoolExecutor

线程池回调函数:

4.协程

猜你喜欢

转载自www.cnblogs.com/lw1095950124/p/10267896.html