当我尝试使用内省来查看线程上可用的方法时.我看不到我期望的内容.
具体来说,我没有看到获取,释放或锁定.为什么是这样?
这是我所看到的:
>>> dir (threading.Lock)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__str__']
Run Code Online (Sandbox Code Playgroud)
你这样做是错的. threading.Lock
不是一个对象.
>>> import threading
>>> threading.Lock
<built-in function allocate_lock>
>>> type(threading.Lock)
<type 'builtin_function_or_method'>
>>> x=threading.Lock()
>>> type(x)
<type 'thread.lock'>
>>> dir(x)
['__enter__', '__exit__', 'acquire', 'acquire_lock', 'locked', 'locked_lock', 'release', 'release_lock']
>>>
Run Code Online (Sandbox Code Playgroud)