tags:

views:

60

answers:

1

When I try to use introspection to look at what methods are available on threading.Lock I don't see what I would expect.

Specifically I don't see acquire, release or locked. Why is this?

Here's what I do see:

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

You're 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']
>>>
S.Lott
Clever. Thanks!
Hortitude