- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
使用下面的代码会导致:
'Collection' object is not callable. If you meant to call the '__getnewargs__' method on a 'Collection' object it is failing because no such method exists.
代码: 来自多处理导入池 db = MongoClient(ip,port)
def f(cursor, arg):
for doc in cursor:
...
p = Pool(4)
for arg in args:
cursor = db[dbName][collName].find()
p.apply_async(f,[cursor, arg])
db.close()
无法弄清楚问题是什么以及如何调试代码。
完整回溯:
Exception in thread Thread-2:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 808, in __bootstrap_inner
self.run()
File "C:\Python27\lib\threading.py", line 761, in run
self.__target(*self.__args, **self.__kwargs)
File "C:\Python27\lib\multiprocessing\pool.py", line 342, in _handle_tasks
put(task)
File "C:\Python27\lib\site-packages\pymongo\collection.py", line 1489, in __call__
self.__name.split(".")[-1])
TypeError: 'Collection' object is not callable. If you meant to call the '__getnewargs__' method on a 'Collection' object it is failing because no such method exists.
最佳答案
您在使用 cursor
时遇到问题。Collection.find
方法返回一个 Cursor
对象,它是一个消耗品。 ( http://api.mongodb.org/python/current/api/pymongo/cursor.html#pymongo.cursor.Cursor.getitem ) 我不知道这是否是异常的原因,但这肯定是一个问题。
两种解决方案:
[:]
或 list
apply_async
中提供光标并使用 clone
方法克隆光标 (http://api.mongodb.org/python/current/api/pymongo/cursor.html#pymongo.cursor.Cursor.clone)关于python - 'Collection' object is not callable error in pymongo with process Pool,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24655925/
我正在使用 boost.pool,但我不知道何时使用 boost::pool<>::malloc和 boost::pool<>::ordered_malloc ? 所以, boost::pool<>:
我目前正在尝试从 anaconda 中的 spy 控制台运行并行代码。我相信问题可能出在我的计算机不允许 anaconda 控制 CPU 核心上,但我不知道如何解决这个问题。 另一个有趣的点是,当我运
在了解 Python 的 multiprocessing 包(对于 Python 3.4 )时,我注意到 multiprocessing.Pool 是在类 BaseContext 中定义的 上下文.p
我有这样的程序: from multiprocessing import Pool import time def f(x): # I make a heavy code here to take t
我有一个模块 A,它通过获取数据并将其发送到模块 B、C、D 等进行分析,然后将它们的结果结合在一起来执行基本的 map/reduce。 但是模块 B、C、D 等似乎不能自己创建多处理池,否则我得到
所以我有一个脚本可以连接到大约 700 个设备并执行一系列命令,然后退出。我开始使用 Multiprocessing.Pool 和 Pool.map 来减少脚本的运行时间,并允许我同时登录多个设备。
在下面的链接中有对 Pool 类的 map 方法的解释。 它似乎阻塞直到结果准备好。这意味着不需要执行 pool.close(); pool.join() 在运行 pool.map 之后,但是它在 t
context 是 class multiprocessing.pool.Pool 构造函数中的可选参数。 Documentation只说: context can be used to specif
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: What's the difference between sending -release or -dra
不确定这是否是正确的论坛。 libvirt 页面链接在这里。如果这需要张贴在不同的地方请告诉我。 virsh pool-define-as 和 create-as 有什么区别?阅读 virsh 的手册
谁能告诉我Spring Cloud Feign Client是否提供或支持Http连接池,如果可以,那么如何配置诸如池大小的设置?我似乎在官方文档中找不到此内容。谢谢你。 最佳答案 通过调查,我将尝试
我在尝试运行 Flask 应用程序时遇到了一些困难。我收到以下导入错误: File "/db/mysql_utils.py", line 2, in import mysql.conne
我有一个 Node 项目,在其中使用 pg-pool 库。我已在我的依赖项中包含以下内容: "@types/pg-pool": "0.0.3", "pg": "^7.3.0", "pg-format"
在 python 2 中,multiprocessing.dummy.Pool 和 multiprocessing.pool.ThreadPool 之间有什么区别吗?源代码似乎暗示它们是相同的。 最佳
这个问题在这里已经有了答案: Concurrent.futures vs Multiprocessing in Python 3 (6 个答案) 关闭 5 年前。 请给我解释一下这两个类有什么区别?
multiprocessing 的文档states以下关于Pool.join() : Wait for the worker processes to exit. One must call clos
我找到了一些资源,但我不确定我是否理解。 我找到的一些资源是: http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb2ff3358411d1829f00
我的 Javafx 应用程序抛出许多非法状态异常,我尚未能够在源中跟踪触发器。 任何人都可以指导我导致此问题的原因以及我应该在哪里查找原因。我很难在这里展示一些代码,因为我不知道是什么原因造成的。 任
参见下面的示例和执行结果: #!/usr/bin/env python3.4 from multiprocessing import Pool import time import os def in
我目前有一个连接到我的主数据库的开放池,它运行良好。但是现在,我想为另一个数据库打开一个新池。我完全按照设置第一个池的方式设置了新池,显然我编辑了数据库名称等。加载 setupHikari() 方法时
我是一名优秀的程序员,十分优秀!