pymongo 无法处理多线程
下面的代码无论是在python2.6还是python3.2中都不起作用。
测试代码:
import pymongo
class A(Thread):
def __init__(self):
Thread.__init__(self)
self.conn = pymongo.Connection('localhost',30000)
self.mongo = self.conn.puppet
self.mongo.authenticate('test','123')
def run(self):
print self.mongo.href.find_one()
A().start()
异常消息:
OperationFailure: database error: unauthorized db:puppet lock
type:-1 client:127.0.0.1
有什么想法如何解决这个问题吗?
the following code does not work, either in python2.6 or python3.2.
Test Code:
import pymongo
class A(Thread):
def __init__(self):
Thread.__init__(self)
self.conn = pymongo.Connection('localhost',30000)
self.mongo = self.conn.puppet
self.mongo.authenticate('test','123')
def run(self):
print self.mongo.href.find_one()
A().start()
Exception Message:
OperationFailure: database error: unauthorized db:puppet lock
type:-1 client:127.0.0.1
Any ideas how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是由于 pymongo 中处理身份验证的方式所致,请参阅 API 文档中的注释 - Pymongo 不会缓存线程之间的身份验证凭据,因此每个线程必须单独进行身份验证。
This is probably due to how authentication is handled in pymongo, see the note in the API docs - Pymongo doesn't cache authentication credentials between threads, so each thread must authenticate individually.