学习版本3.5.2
Lock() 创建一个Lock对象并返回
RLock() 创建一个RLock对象并返回
active_count() 返回当前未被阻塞的线程的数量
current_thread() 返回当前的线程对象
enumerate() 返回当前未被阻塞的对象的list
setprofile(func)和settrace(func) 设置一个function在所有的线程对象的run()方法运行之前调用
stack_size(...) 修改创建线程时候使用的栈空间大小,参数为0(使用平台的默认参数或者设置好的参数)或者大于32768(32k)的整数。返回创建线程时候使用的栈空间大小(0(使用平台的默认参数或者设置好的参数))
实验代码:
#/usr/bin/python3
# -*- utf-8 -*-
#学习版本3.5.2
import threading
import time
class Chick(threading.Thread):
def __init__(self, name=""):
super(Chick, self).__init__(name=name)
threading.settrace(funct)
threading.setprofile(funcp)
def run(self):
print(self.getName(),": 等待中")
time.sleep(3)
def funct(*args):
print("trace")
print(args)
def funcp(*args):
print("profile")
print(args)
if __name__ == "__main__":
c1 = Chick(name="A")
c2 = Chick(name="B")
c3 = Chick(name="C")
c1.start()
c2.start()
c3.start()
print(threading.active_count())
print(threading.current_thread().getName())
print(threading.stack_size(65536))
print(threading.stack_size())
print("main")
运行结果
trace
(<frame object at 0x101ca9048>, 'call', None)
profile
(<frame object at 0x101ca9048>, 'call', None)
trace
(<frame object at 0x101c3ca38>, 'call', None)
profile
(<frame object at 0x101c3ca38>, 'call', None)
trace
(<frame object at 0x101ca6558>, 'call', None)
profile
(<frame object at 0x101ca6558>, 'call', None)
profile
(<frame object at 0x101ca6558>, 'return', 'A')
profile
(<frame object at 0x101c3ca38>, 'return', 'A')
profile
(<frame object at 0x101ca9048>, 'c_call', <built-in function print>)
A : 等待中
profile
(<frame object at 0x101ca9048>, 'c_return', <built-in function print>)
profile
(<frame object at 0x101ca9048>, 'c_call', <built-in function sleep>)
trace
(<frame object at 0x101ca9200>, 'call', None)
trace
4
(<frame object at 0x101ca93b8>, 'call', None)
MainThread
profile
0
65536
(<frame object at 0x101ca93b8>, 'call', None)
main
profile
trace
(<frame object at 0x101ca9200>, 'call', None)
(<frame object at 0x101c3ca38>, 'call', None)
profile
...