嗨,大家好,我有python2.7.5
的下一个环境:
flask==0.10.1
flask-wtf==0.8.4
jinja2==2.7
werkzeug==0.9.1
flask-mongoengine==0.7.0
mongoengine==0.8.2
pymongo==2.5.2
uwsgi==1.9.13
from flask import Flask
from flask.ext.mongoengine import Document, MongoEngine
from mongoengine import StringField
class Config(object):
DEBUG = True
MONGODB_HOST = ('mongodb://localhost:27017,localhost:27018/'
'test?replicaSet=rs0')
MONGODB_DB = True
app = Flask(__name__)
app.config.from_object(Config)
MongoEngine(app)
class Test(Document):
test = StringField(default='test')
meta = {
'allow_inheritance': False,
}
def __unicode__(self):
return self.test
Test(test='test1').save()
@app.route('/')
def hello_world():
return unicode(Test.objects.first())
if __name__ == '__main__':
app.run('0.0.0.0', 8080, True)
server {
listen 80;
server_name localhost;
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi.sock;
}
}
/path/to/env/bin/uwsgi \
--module app:app \
--env /path/to/env/ \
--pythonpath /path/to/app/ \
--socket /tmp/uwsgi.sock \
--pidfile /tmp/uwsgi.pid \
--daemonize /tmp/uwsgi.log \
--processes 2 \
--threads 2 \
--master
mongod --port 27017 --dbpath /path/to/mongo/data/rs0-0 --replSet rs0 \
--smallfiles --oplogSize 128
mongod --port 27018 --dbpath /path/to/mongo/data/rs0-1 --replSet rs0 \
--smallfiles --oplogSize 128
rsconf = {
_id: "rs0",
members: [{_id: 0, host: "127.0.0.1:27017"}]
};
rs.initiate(rsconf);
rs.add("127.0.0.1:27018");
...
File "/path/to/app/replica.py", line 33, in hello_world
return unicode(Test.objects.first())
File "/path/to/env/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 325, in first
result = queryset[0]
File "/path/to/env/local/lib/python2.7/site-packages/mongoengine/queryset/queryset.py", line 211, in __getitem__
return queryset._document._from_son(queryset._cursor[key],
File "/path/to/env/local/lib/python2.7/site-packages/pymongo/cursor.py", line 470, in __getitem__
for doc in clone:
File "/path/to/env/local/lib/python2.7/site-packages/pymongo/cursor.py", line 814, in next
if len(self.__data) or self._refresh():
File "/path/to/env/local/lib/python2.7/site-packages/pymongo/cursor.py", line 763, in _refresh
self.__uuid_subtype))
File "/path/to/env/local/lib/python2.7/site-packages/pymongo/cursor.py", line 700, in __send_message
**kwargs)
File "/path/to/env/local/lib/python2.7/site-packages/pymongo/mongo_replica_set_client.py", line 1546, in _send_message_with_response
raise AutoReconnect(msg, errors)
pymongo.errors.AutoReconnect: No replica set primary available for query with ReadPreference PRIMARY
mongoengie==0.7.10
而不是ReplicaSetConnection
中的MongoReplicaSetClient
的mongoengine==0.8.2
时,我有下一个异常(exception):pymongo.errors.AutoReconnect: 127.0.0.1:27017: [Errno 104] Connection reset by peer
pymongo.errors.AutoReconnect: No replica set primary available for query with ReadPreference PRIMARY
pymongo.errors.AutoReconnect: 127.0.0.1:27017: [Errno 111] Connection refused
pymongo.errors.AutoReconnect: No replica set primary available for query with ReadPreference PRIMARY
pymongo.errors.AutoReconnect: not master and slaveOk=false
--master
):/path/to/env/bin/uwsgi \
--module app:app \
--env /path/to/env/ \
--pythonpath /path/to/app/ \
--socket /tmp/uwsgi.sock \
--pidfile /tmp/uwsgi.pid \
--daemonize /tmp/uwsgi.log \
--processes 1 \
--threads 2
/path/to/env/bin/python app.py
self.__schedule_refresh()
的行为有所不同:rs_state
有两个成员:活跃于up == True
,活跃于up == False
。 rs_state
有一个 Activity 成员up == True
。 rs_state
有两个成员:活跃于up == True
,活跃于up == False
。 rs_state
有两个成员:活跃于up == True
,活跃于up == False
(未更改)。 self.__schedule_refresh(sync=sync)
也具有不同的行为:rs_state
有一个活跃成员up == True
。 rs_state
有两个活跃的up == True
成员,并增加了up == True
。 rs_state
有两个活跃于up == True
的成员,并增加了up == False
。 rs_state
具有两个活跃的成员up == True
,并增加了up == False
(未更改)。 __schedule_refresh
):def __schedule_refresh(self, sync=False):
"""Awake the monitor to update our view of the replica set's state.
If `sync` is True, block until the refresh completes.
If multiple application threads call __schedule_refresh while refresh
is in progress, the work of refreshing the state is only performed
once.
"""
self.__monitor.schedule_refresh()
if sync:
self.__monitor.wait_for_refresh(timeout_seconds=5)
最佳答案
尝试使用uwsgi --lazy-apps
选项。 MongoReplicaSetClient产生一个副本集MonitorThread,并且该线程无法在uwsgi worker进程派生中幸存。 --lazy-apps
将在每个工作进程中初始化pymongo MonitorThread。
https://stackoverflow.com/questions/17534642/
相关文章:
c# - MongoDB + C# 驱动程序 + 查询元素数组,其中每个数组元素包含要查询的子文档
mongodb - 结合 Neo4J 和 MongoDB : Consistency
mongodb - 与 skip() 和 limit() 一起使用的 Distinct() 命令
php - 为什么这种 mongo 排序在 PHP 中不起作用?
c# - 使用 MongoDB 的 C# 驱动程序进行多字段查询
node.js - NodeJS ExpressJS PassportJS - 仅用于管理页面