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.协程

day 34 线程队列 线程池 协程 Greenlet \Gevent 模块的更多相关文章

  1. 线程队列 concurrent 协程 greenlet gevent

    死锁问题 所谓死锁:是指两个或两个以上的进程或线程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去.此时称系统处于死锁状态或系统产生了死锁,这些永远在互相等待的进 ...

  2. python 协程 greenlet gevent

    一.并发的本质 切换+保存状态 cpu正在运行一个任务,会在两种情况下切走去执行其他的任务(切换由操作系统强制控制),一种情况是该任务发生了阻塞,另外一种情况是该任务计算的时间过长时间片到了 二.协程 ...

  3. python 线程(其他方法,队列,线程池,协程 greenlet模块 gevent模块)

    1.线程的其他方法 from threading import Thread,current_thread import time import threading def f1(n): time.s ...

  4. GIL解释器,协程,gevent模块

    GIL解释器锁 在Cpython解释器中,同一个进程下开启的多线程,同一时刻只能有一个线程执行,无法利用多核优势 首先需要明确的一点是GIL并不是Python的特性,它是在实现Python解析器(CP ...

  5. 单线程实现并发——协程,gevent模块

    一 并发的本质 1 切换 2 保存状态 二 协程的概念 协程,又称微线程,纤程.英文名Coroutine.单线程下实现并发,用户从应用程序级别控制单线程下任务的切换,注意一定是遇到I/O才切. 协程的 ...

  6. Python程序中的协程操作-gevent模块

    目录 一.安装 二.Gevent模块介绍 2.1 用法介绍 2.2 例:遇到io主动切换 2.3 查看threading.current_thread().getName() 三.Gevent之同步与 ...

  7. python并发编程之线程剩余内容(线程队列,线程池)及协程

    1. 线程的其他方法 import threading import time from threading import Thread,current_thread def f1(n): time. ...

  8. day35:线程队列&进程池和线程池&回调函数&协程

    目录 1.线程队列 2.进程池和线程池 3.回调函数 4.协程:线程的具体实现 5.利用协程爬取数据 线程队列 1.线程队列的基本方法 put 存 get 取 put_nowait 存,超出了队列长度 ...

  9. python队列、线程、进程、协程

    目录: 一.queue 二.线程 基本使用 线程锁 自定义线程池 生产者消费者模型(队列) 三.进程 基本使用 进程锁 进程数据共享 默认数据不共享 queues array Manager.dict ...

随机推荐

  1. SpringMVC配置及使用

    SpringMVC基本配置 SpringMVC是基本请求响应模式的框架. 在项目中集成SpringMVC框架首先需要导入相关的jar包,所需包具体如下: commons-dbcp.jar common ...

  2. Codeforces Round #212 (Div. 2) C. Insertion Sort

    C. Insertion Sort Petya is a beginner programmer. He has already mastered the basics of the C++ lang ...

  3. Java读取键盘输入

    三种方法分别如下: 方法一:从控制台接收一个字符,然后将其打印出来 import java.io.*; public static void main(String [] args) throws I ...

  4. synchronized(六)

    package com.bjsxt.base.sync006;/** * 锁对象的改变问题 * @author alienware * */public class ChangeLock { priv ...

  5. ios中xib文件的用法

    ZQRView文件: // // ZQRView.h // // // Created by zzqqrr on 17/8/20. // // #import <UIKit/UIKit.h> ...

  6. 解决 java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()L的问题

    <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</a ...

  7. usort 函数

    function getNameFromNumber($num){ // Used to figure out what the Excel column name would be for a gi ...

  8. jquery.datatables设置列隐藏的方法

    项目需要根据权限设置表格(使用Juqery.datatables,版本:1.10.16)某列显示或隐藏,百度后有两种实现方法: 1.在columns中设置: columns:[{data:" ...

  9. 解释生成器(generator)于函数的不同,并实现和使用简单generator?

    生成器和函数的主要区别在于函数return avalue,生成器yield  a  value,同事标记或记忆point of the yield 以便在下次调用时从标记点恢复执行,yield使用函数 ...

  10. 使用json通过telegraf生成metrics(摘自telegraf github文档)

    JSON: The JSON data format flattens JSON into metric fields. NOTE: Only numerical values are convert ...