我最近从本地 web.py/apache 设置转移到共享主机,我正在尝试匹配我的家庭配置。出现的一个问题是 OperationalError "MySQL server has gone away"。在互联网上搜索,遇到此错误的人往往会在几个小时内不活跃。这在几秒钟之间发生在我身上。
我已经使用 mod_wsgi 的 application() 函数示例确认我实际上是在守护进程模式下运行的。不过,我担心的一个问题是,如果我将 web.ctx.orm 吐到错误日志中,它似乎是每个请求的新对象。我的 sqlalchemy 会话对象在页面请求之间不应该相同吗?
这是我的 python 代码和我的 apache 设置的一部分。在这台新机器上,我以前在家用机器上没有遇到过什么问题吗?
def load_sqla(handler):
web.ctx.orm = scoped_session(sessionmaker(bind=engine))
try:
try:
return handler()
except web.HTTPError:
web.ctx.orm.commit()
raise
except:
web.ctx.orm.rollback()
raise
finally:
web.ctx.orm.commit()
# If the above alone doesn't work, uncomment
# the following line:
web.ctx.orm.expunge_all()
... urls and controllers ...
app = web.application(urls, globals(), autoreload=False)
app.add_processor(load_sqla)
application = app.wsgifunc()
这是我的 apache 设置的一部分。
WSGIDaemonProcess app processes=1 threads=1 python-path=/home/net/
public_html/myapp
WSGIProcessGroup app
WSGIScriptAlias /myapp /home/net/public_html/myapp/managio.py
<Directory "/home/stratton/public_html/myapp">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
</Directory>