在Djang中捕获操作错误1040

2024-06-28 10:54:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我在一个共享服务器上运行我的Django网站,因此,我的用户不时会收到一个内部服务器错误500页,这是由于将自己标识为(1040, "Too Many Connections")的特定操作错误异常造成的。我有一个自定义的500.html页面和handler500 = 'myapp.views.error500'在我的urls.py中,error500方法是:

def error500(request):
    exctype, value = sys.exc_info()[:2]
    msg = ''
    if exctype == OperationalError:
        msg = 'We\'re busy at the moment -- please reload this page in a little while.'
    return render_to_response('500.html', {'msg': msg})

在这里,我从MySQLdb模块导入OperationalError。MySQL的“1040”属性有多少错误呢?在我浏览我自己的网站时,我怎么能不用等着看看共享的MySQL服务器是否超载了呢?在


Tags: django用户服务器网站html错误mysqlmsg
1条回答
网友
1楼 · 发布于 2024-06-28 10:54:19

以下是对我有效的方法:

def error500(request):
    exctype, value = sys.exc_info()[:2]
    msg = ''
    if exctype == OperationalError and value.args[0] == 1040:
        msg = 'We\'re busy at the moment   please reload this page in a little while.'
    return render_to_response('500.html', {'msg': msg})

我通过编写一个bash脚本来测试它,打开到MySQL服务器的151个连接(最多),然后访问我的页面尝试打开第152个。。。在

相关问题 更多 >