python 自省(introspection)不显示 Lock 的函数

标签 python

当我尝试使用内省(introspection)来查看 threading.Lock 上可用的方法时,我没有看到我期望的结果。

具体来说,我没有看到获取、释放或锁定。这是为什么?

这是我所看到的:

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

最佳答案

你做错了。 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']
>>>

关于python 自省(introspection)不显示 Lock 的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/394300/

相关文章:

python - 如何从 Python 脚本中创建存储过程?

python - 将 PyQT 表项从 QComboBox 更改为 QTableWidgetItem

python - 在循环中使用 numpy load 时内存溢出

python - 多态性和pybind11

python - 如何从 *.xlsm 中提取工作表并将其保存为 Python 中的 *.csv?

python - 通过 Azure Databricks Notebook URL 传递参数

python - 正则表达式匹配特定长度的数字

python - Scipy: PIL 逊相关性总是返回 1

python - 如何测试我的神经网络开发的 Tensorflow?

Python惰性列表