Python introspection not showing Lock functions

When I try to use introspection to see what methods are available for threading.Lock, I don't see what I would expect.

In particular, I don't see receiving, releasing or blocking. Why is this?

This is what I see:

>>> dir (threading.Lock)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__str__']

      

+1


source to share


1 answer


You are doing it wrong. threading.Lock

is not an object.



>>> 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']
>>>

      

+5


source







All Articles