<p>Python驱动程序中的每个方法都遵循<a href="https://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 0008</a>,除非我大错特错</p>
<p>在Pymongo中,您需要使用<a href="http://api.mongodb.org/python/current/api/pymongo/database.html#pymongo.database.Database.current_op" rel="nofollow">^{<cd1>}</a>方法来获取有关当前正在运行的操作的信息。在</p>
<pre><code>from pymongo import MongoClient
client = MongoClient(host="myhost.com")
db = client.mydb
infos = db.current_op()
</code></pre>
<p>当然,如果要在结果集中列出当前空闲的操作,请将位置或关键字参数<code>include_all</code>设置为<code>True</code></p>
^{pr2}$
<p>演示:</p>
<pre><code>In [8]: db.current_op()
Out[8]:
{'inprog': [{'active': True,
'client': '127.0.0.1:54268',
'connectionId': 2,
'desc': 'conn2',
'lockStats': {},
'locks': {},
'microsecs_running': 45,
'ns': 'admin.$cmd',
'numYields': 0,
'op': 'command',
'opid': 793,
'query': {'$all': False, 'currentOp': 1},
'secs_running': 0,
'threadId': '140272266217216',
'waitingForLock': False}],
'ok': 1.0}
</code></pre>
<p>要发出MongoDB命令,驱动程序提供<a href="http://api.mongodb.org/python/current/api/pymongo/database.html#pymongo.database.Database.command" rel="nofollow">^{<cd4>}</a>方法</p>