MySQL服务器消失了
我最近从本地 web.py/apache 设置转移到共享主机 我正在尝试匹配我的家庭配置。有一个问题就是 弹出一个操作错误“MySQL 服务器已消失”。 网上搜了一下,有遇到这个错误的人 往往在几个小时内不活动。这发生在我身上 几秒钟之间。
我已经使用 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>
I've recently moved from my local web.py/apache setup to a shared host
and I'm trying to match my home configuration. One issue that is
popping up is an OperationalError "MySQL server has gone away".
Searching around the internet, people who come across this error
tended to be inactive for the space of hours. This happens to me
between seconds.
I've confirmed using mod_wsgi's application() function example that I
am in fact running in daemon mode. One issue though, that concerns me
is that if I spit out web.ctx.orm to the error log, it appears to be a
new object for each request. Shouldn't my sqlalchemy session object be the same
between page requests?
Here's my python code and a portion of my apache setup. Is there
anything that would cause problems on this new machine I hadn't had
before on my home machine?
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()
and here's a portion of my apache setup.
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请查看文档:http://code.google.com/p/modwsgi/ wiki/ConfigurationDirectives#WSGIDaemonProcess
设置
processes=1
实际上会启用多处理,这可能就是为什么您可以并发访问同一 sql 连接。另外,您似乎正在使用 SQLAlchemy,所以也许尝试在制作引擎时打开 QueuePool 或 NullPool 使用?
Check the docs at: http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess
Setting
processes=1
actually leaves multiprocessing on, which may be why you're getting concurrent access to the same sql connection.Also it appears you're using SQLAlchemy, so maybe try turning on QueuePool or NullPool use when you make your engine?