我有一个在 Gunicorn 中运行的 Flask-SQLAlchmey 应用程序连接到 PostgreSQL 数据库,但我无法确定pool_size
值应该是什么以及我应该期望有多少数据库连接。
这是我对事情如何运作的理解:
到目前为止,这是正确的吗?如果这是正确的,那么对于在 Gunicorn 中运行的同步 Flask 应用程序:
是否有理由pool_size
应该大于线程数?那么,对于启动的 gunicorn 应用程序gunicorn --workers=5 --threads=2 main:app
应该pool_size
是 2?如果我只使用工人,而不使用线程,是否有任何理由pool_size
大于 1?
我在网上看过人们使用__getattr__
Django模型的例子,但每当我尝试时我都会遇到错误.(Django 1.2.3)
我__getattr__
在普通物体上使用时没有任何问题.例如:
class Post(object):
def __getattr__(self, name):
return 42
Run Code Online (Sandbox Code Playgroud)
工作得很好......
Run Code Online (Sandbox Code Playgroud)>>> from blog.models import Post >>> p = Post() >>> p.random 42
现在,当我尝试使用Django模型时:
from django.db import models
class Post(models.Model):
def __getattr__(self, name):
return 42
Run Code Online (Sandbox Code Playgroud)
并在解释器上测试它:
Run Code Online (Sandbox Code Playgroud)>>> from blog.models import Post >>> p = Post() ERROR: An unexpected error occurred while tokenizing input The
跟踪回溯可能已损坏或无效错误消息为:('多行语句中的EOF',(6,0))
-------------------------------------------------- ------------------------- TypeError
Traceback(最近一次调用最后一次)/ Users/josh/project/in()
/Users/josh/project/lib/python2.6/site-packages/django/db/models/base.pyc in init(self,*args,**kwargs)338如果kwargs:339引发TypeError("'%s '是这个函数"%kwargs.keys()[0])无效的关键字参数- > 340 signals.post_init.send(发件人=自我.类,实例=自我)341 342 DEF 再版(个体):
/Users/josh/project/lib/python2.6/site-packages/django/dispatch/dispatcher.pyc …
我在本地运行一个网站,所有流量都通过NGinx路由,然后NGinx将请求发送到Apache页面并提供静态文件.在Chrome,Safari,IE等中完美运行
但是,每当我在Firefox中打开网站时,我都会收到以下错误:
502 Bad Gateway
nginx/0.7.65
Run Code Online (Sandbox Code Playgroud)
如果我清除缓存和cookie,然后重新启动FireFox,我可以在错误返回之前加载一次或两次站点.我试过Firefox 3.6和3.5都有同样的问题.
这是我的Nginx配置的样子:
worker_processes 2;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name local.mysite.amc;
root /Users/joshmaker/Sites/mysite;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://local.mysite.amc:8080;
}
include /opt/local/etc/nginx/rewrite.txt;
}
server {
include /opt/local/etc/nginx/mime.types;
listen 80;
server_name local.static.mysite.amc;
root /Users/joshmaker/Sites/mysite;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
}
Run Code Online (Sandbox Code Playgroud)
这是Firefox在error.log文件中生成的错误:
[error] 11013#0: *26 kevent() reported that connect() failed (61: Connection refused) while connecting to upstream
[error] 11013#0: *30 …
Run Code Online (Sandbox Code Playgroud) 我正在写一个像报纸一样工作的Django应用程序.我有文章,然后我有在某些上下文中出现的那些文章的自定义版本.所以,我可以在报纸的头版上看到一篇文章的版本,该文章的文章原始标题较短.所以我有:
class Article(models.Model):
""" A newspaper article with lots of fields """
title = models.CharField(max_length=255)
content = models.CharField(max_length=255)
# Lots of fields...
Run Code Online (Sandbox Code Playgroud)
我想要一个CustomArticle对象作为文章的代理,但有一个可选的替代标题:
class CustomArticle(Article):
""" An alternate version of a article """
alternate_title = models.CharField(max_length=255)
@property
def title(self):
""" use the alternate title if there is one "
if self.custom_title:
return self.alternate_title
else:
return self.title
class Meta:
proxy = True
# Other fields and methods
Run Code Online (Sandbox Code Playgroud)
不幸的是,我无法向代理添加新字段:
TypeError:包含代理模型'CustomArticle'不允许的模型字段的抽象基类
所以,我可以这样做:
class CustomArticle(models.Model):
# Other methods...
original = models.ForeignKey('Article')
def __getattr__(self, name): …
Run Code Online (Sandbox Code Playgroud) 我刚刚使用自制软件在干净的Mac OS X Snow Leopard安装上安装Python 2.7.2,但似乎无法让PIP很好地使用它.
以下是我采取的步骤:
brew install python --framework
--universal
.zsrc
/System/Library/Frameworks/Python.framework/Versions/Current
到/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/Current
easy_install
安装pip
这些步骤似乎已经奏效:
$ brew doctor
Your system is raring to brew.
$ which python
/usr/local/bin/python
$ python --version
Python 2.7.2
$ which easy_install
/usr/local/share/python/easy_install
$ which pip
/usr/local/bin/pip
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用pip安装东西时,例如$ pip install ipython
我收到此错误消息'/System/Library/Frameworks/Python.framework/Versions/2.6/share': Permission denied
为什么pip仍在尝试安装旧的Python 2.6位置?如何让它安装到/usr/local/Cellar/python/2.7.2/
等等?