应用报 502 了

46 views
Skip to first unread message

vfasky

unread,
Nov 9, 2012, 12:47:37 AM11/9/12
to sae-p...@googlegroups.com

Alan Chan

unread,
Nov 9, 2012, 1:45:49 AM11/9/12
to sae-p...@googlegroups.com
用的tornado worker?

On Fri, Nov 9, 2012 at 1:47 PM, vfasky <vfa...@gmail.com> wrote:

--
邮件来自: SAE Python 邮件列表
发言: sae-p...@googlegroups.com
退订: sae-python+...@googlegroups.com (向此发空信即退!)
 
 

PastedGraphic-1.tiff

Shuai Lin

unread,
Nov 9, 2012, 1:56:16 AM11/9/12
to sae-p...@googlegroups.com
厉害,index.wsgi 贴出来看看
PastedGraphic-1.tiff

vfasky

unread,
Nov 9, 2012, 2:04:14 AM11/9/12
to sae-p...@googlegroups.com

在 2012-11-9,下午2:45,Alan Chan <chanf...@gmail.com> 写道:

用的tornado worker?

On Fri, Nov 9, 2012 at 1:47 PM, vfasky <vfa...@gmail.com> wrote:
<PastedGraphic-1.tiff>

--
邮件来自: SAE Python 邮件列表
发言: sae-p...@googlegroups.com
退订: sae-python+...@googlegroups.com (向此发空信即退!)
 
 

vfasky

unread,
Nov 9, 2012, 2:04:56 AM11/9/12
to sae-p...@googlegroups.com
#coding=utf-8

'''
  SAE 的 入口文件
  --------------

  @author vfa...@gmail.com
'''

import sys
import os

# 设置系统编码为utf8
code = sys.getdefaultencoding()
if code != 'utf8':
    reload(sys)
    sys.setdefaultencoding('utf8')


# 加入virtualenv.bundle目录
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'virtualenv.bundle'))

# 加入第三方类库搜索路径
sys.path.append(os.path.join(os.path.dirname(__file__), 'modules'))

# 加载程序配置
from catke import config
from xcat import cache
# 引入Database
from xcat import Database

# 取缓存实例
cache.client = getattr(cache, config.settings['xcat_cache'][config.settings['run_mode']])()


# 加载数据库配置
Database.load_config(
    config.settings['database'].get(config.settings['run_mode'],False)
)

import xcat.web
import xcat.plugins
from catke import uimodules

# 加载UImodel
config.settings['ui_modules'] = uimodules

# run taoke
from catke.handlers import *
application = xcat.web.Application([],**config.settings)

# 为插件注册 application
xcat.plugins.register_app(application)
# 绑定ACL
xcat.web.Route.acl(application)

# 绑定路由
xcat.web.Route.routes(application)


# 本地环境,启动 server
if 'SERVER_SOFTWARE' not in os.environ:
    import tornado.ioloop
    application.listen(config.settings['port'][config.settings['run_mode']])
    tornado.ioloop.IOLoop.instance().start()

在 2012-11-9,下午2:56,Shuai Lin <linshu...@gmail.com> 写道:

厉害,index.wsgi 贴出来看看


On Fri, Nov 9, 2012 at 1:47 PM, vfasky <vfa...@gmail.com> wrote:
<PastedGraphic-1.tiff>

--
邮件来自: SAE Python 邮件列表
发言: sae-p...@googlegroups.com
退订: sae-python+...@googlegroups.com (向此发空信即退!)
 
 

vfasky

unread,
Nov 9, 2012, 2:08:10 AM11/9/12
to sae-p...@googlegroups.com
在后台唯一能看到的日志:

              - [2012/11/09 13:57:36] - IOError: Unable to open 'index.wsgi' tc28      

index.wsgi  是存在于根目录的,且有内容
在 2012-11-9,下午2:45,Alan Chan <chanf...@gmail.com> 写道:

用的tornado worker?

On Fri, Nov 9, 2012 at 1:47 PM, vfasky <vfa...@gmail.com> wrote:
<PastedGraphic-1.tiff>

--
邮件来自: SAE Python 邮件列表
发言: sae-p...@googlegroups.com
退订: sae-python+...@googlegroups.com (向此发空信即退!)
 
 

Alan Chan

unread,
Nov 9, 2012, 2:10:21 AM11/9/12
to sae-p...@googlegroups.com
tornado server在有些异常的情况下会直接断开连接,没有任何回复,这个会导致nginx直接返回502,这种情况下需要查看日志。

1. 打开tornado框架的debug开关

vfasky

unread,
Nov 9, 2012, 2:21:52 AM11/9/12
to sae-p...@googlegroups.com
debug 是一直打开的

版本3(http://3.taokeweb.sinaapp.com/ )同 版本4 用的是同一套框架。 不同之处在于: 版本4 将数据库部份改成读写分离

在本地的环境跑是通过的。 但到线上一点错误信息都无,很难排查

vfasky

unread,
Nov 9, 2012, 2:25:26 AM11/9/12
to sae-p...@googlegroups.com
为了测试不是代码的问题,我新建了一个版本 5
http://5.taokeweb.sinaapp.com/ 一样报 502
index.wsgi 的代码:

import
sae

def
app(environ, start_response):
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain')]
    start_response(status, response_headers)
    return ['Hello, world!']

application
= sae.create_wsgi_app(app)





vfasky

unread,
Nov 9, 2012, 2:30:11 AM11/9/12
to sae-p...@googlegroups.com
sorry , 用错示例了,用官方的 tornado 无问题!

Alan Chan

unread,
Nov 9, 2012, 2:35:17 AM11/9/12
to sae-p...@googlegroups.com
看了一下index.wsgi的代码,日志没了跟下面这个有关:

# 设置系统编码为utf8
code = sys.getdefaultencoding()
if code != 'utf8':
    reload(sys)
    sys.setdefaultencoding('utf8')
因为现在python的日志输出是通过在加载应用的时候动态替换了sys.stdout和sys.stderr来实现的,如果reload的话,会导致sys.stdout和sys.stderr又恢复为默认的系统标准输出和标准错误输出。

暂时的解决方案:

import sys
_stdout, _stderr = sys.stdout, sys.stderr
reload(sys)
sys.stdout, sys.stderr = _stdout, _stderr
sys.setdefaultencoding('utf8')




2012/11/9 vfasky <vfa...@gmail.com>

vfasky

unread,
Nov 9, 2012, 2:47:37 AM11/9/12
to sae-p...@googlegroups.com
灰常感谢, 有了日志,问题顺利解决

Alan Chan

unread,
Nov 9, 2012, 5:05:17 AM11/9/12
to sae-p...@googlegroups.com
reload导致日志不见的问题已经fix,下周一更新到线上。

2012/11/9 vfasky <vfa...@gmail.com>
Reply all
Reply to author
Forward
0 new messages