import threading
import inspect
import ctypes def _async_raise(tid, exc_type):
"""raises the exception, performs cleanup if needed"""
if not inspect.isclass(exc_type):
raise TypeError("Only types can be raised (not instances)")
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exc_type))
if res == 0:
raise ValueError("invalid thread id")
elif res != 1:
# """if it returns a number greater than one, you're in trouble,
# and you should call it again with exc=NULL to revert the effect"""
ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0)
raise SystemError("PyThreadState_SetAsyncExc failed") class Thread(threading.Thread):
def raise_exc(self, exc_type):
"""raises the given exception type in the context of this thread"""
_async_raise(ctypes.c_long(self.ident), exc_type) def terminate(self):
"""raises SystemExit in the context of the given thread, which should
cause the thread to exit silently (unless caught)"""
self.raise_exc(SystemExit)

Python 为threading.Thread添加 terminate的更多相关文章

  1. python:threading.Thread类的使用详解

    Python Thread类表示在单独的控制线程中运行的活动.有两种方法可以指定这种活动: 1.给构造函数传递回调对象 mthread=threading.Thread(target=xxxx,arg ...

  2. python的threading.Thread线程的start、run、join、setDaemon

    Pycharm整体看下Thread类的内容:模拟的是Java的线程模型 表示方法method,上面的锁头表示这个是类内部的方法,从方法名字命名规范可以看出,都是_和__开头的,一个下划线表示是子类可以 ...

  3. python中threading的用法

    摘自:http://blog.chinaunix.net/uid-27571599-id-3484048.html 以及:http://blog.chinaunix.net/uid-11131943- ...

  4. python进阶笔记 thread 和 threading模块学习

    Python通过两个标准库thread和threading提供对线程的支持.thread提供了低级别的.原始的线程以及一个简单的锁.threading基于Java的线程模型设计.锁(Lock)和条件变 ...

  5. [python]多线程模块thread与threading

    Python通过两个标准库(thread, threading)提供了对多线程的支持 thread模块 import time import thread def runner(arg): for i ...

  6. python threading.thread

    Thread 是threading模块中最重要的类之一,可以使用它来创建线程.有两种方式来创建线程:一种是通过继承Thread类,重写它的run方法:另一种是创建一个threading.Thread对 ...

  7. python语言中threading.Thread类的使用方法

    1. 编程语言里面的任务和线程是很重要的一个功能.在python里面,线程的创建有两种方式,其一使用Thread类创建 # 导入Python标准库中的Thread模块 from threading i ...

  8. Python之threading多线程,多进程

    1.threading模块是Python里面常用的线程模块,多线程处理任务对于提升效率非常重要,先说一下线程和进程的各种区别,如图 概括起来就是 IO密集型(不用CPU) 多线程计算密集型(用CPU) ...

  9. Python(多线程threading模块)

    day27 参考:http://www.cnblogs.com/yuanchenqi/articles/5733873.html CPU像一本书,你不阅读的时候,你室友马上阅读,你准备阅读的时候,你室 ...

随机推荐

  1. BluetoothFindRadioClose 函数

    BOOL BluetoothFindRadioClose( HBLUETOOTH_RADIO_FIND hFind );关闭与查找蓝牙无线电相关的枚举句柄.参数: hFind Enumeration ...

  2. HTTP之首部

    http报文包括起始行.首部和主体.     HTTP请求/响应起始行 请求组成: 方法 + 请求URL + HTTP版本 响应组成: HTTP版本 + 数字状态码 + 描述状态的原因短语    HT ...

  3. [51nod1119]机器人走方格V2

    解题关键: 1.此题用dp的方法可以看出,dp矩阵为杨辉三角,通过总结,可以得出 答案的解为$C_{n + m - 2}^{n - 1}$ 2.此题可用组合数学的思想考虑,总的步数一共有$n+m-2$ ...

  4. windows7 8 mac 安装docker

    安装: 下载 DockerToolbox.exe 苹果的也可以用这个链接下载 一直点击下一步(网络要求很高安装时,网络不好会报错 多点几次就好了)

  5. Tomcat+Nginx实现动静分离

    Tomcat是我们经常用的服务器,轻便快捷,但是数据量大的时候,会影响访问.响应速度,这时Nginx就出现了. Nginx可做反向代理.负载均衡.动态与静态资源的分离的工作,这里我们就用它来做动静分离 ...

  6. javascript的DI

    学习AngularJS的原因之一就是觉得他的DI很牛叉,为了更好的学习,在研究源码之前,想自己按照自己的思路先实现个DI,希望这个思路能够对学习源码有帮助. (function(){ var conf ...

  7. pig flatten

    今天通过不断的尝试,终于知道这个flatten的用法了.其实吧,有时候关键是要test,才能充分理解解说.不过,同事给说的有点问题,误导了我.整的我一直没明白怎么回事. 这是官方的解释: The FL ...

  8. 9、IPA通路分析相关网页教程

    IPA FAQ: http://ingenuity.force.com/ipa/IPATutorials# ####有各种相关教程和帮助文件. IPA 分析结果展示: http://www.lucid ...

  9. MD5Init-MD5Update-MD5Final

    MD5Init是一个初始化函数,初始化核心变量,装入标准的幻数 MD5Update是MD5的主计算过程,inbuf是要变换的字节串,inputlen是长度,这个函数由getMD5ofStr调用,调用之 ...

  10. hdu 5147 Sequence II (树状数组 求逆序数)

    题目链接 Sequence II Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...