CherryPy:需要异常处理帮助

时间:2013-11-16 01:09:26

标签: python apache mod-wsgi cherrypy

我有一个html.app,它异步地询问来自CherryPy Backend的JSON数据模型。 JSON数据的大小有点大1.74 MB。加载和渲染数据大约需要1秒。该应用程序在独立时工作正常。但是,当我通过mod_wsgi将它附加到Apache Web服务器时,我立即开始注意到问题。

在数据连接关闭之前刷新html页面时,mod_wsgi会触发其臭名昭着的

  mod_wsgi (pid=917): Exception occurred processing WSGI script '/myapp_path/WebApp.py'
  IOError: failed to write data, referer: https://domain/etc/padmin/
  ENGINE Started monitor thread 'Session cleanup'.
  ENGINE Started monitor thread 'Session cleanup'.

我理解Apache在WSGI有机会将数据完整地提供给客户端之前关闭了数据连接。这不是什么大问题,但它引发了某种内部异常,我无法陷入或不知道如何。 CherryPy的默认行为是在发生无法处理的异常时重置会话。我需要更改CherryPy的行为,以便当客户选择不等待数据完成时,它不会重置活动会话。我更喜欢陷阱和抑制mod_wsgi异常解决方案,但如果不可能,我会选择阻止“会话清理”操作,如果发生无法处理的异常。 任何帮助将不胜感激。

更新 我将我的问题追溯到不正确配置的会话存储类型。它应该是file但由于非法值,它变成了默认的ram类型。问题得到了解决。

1 个答案:

答案 0 :(得分:1)

我编写python,所以我不确定html如何处理异常,但是应该通过“try and catch”系统来实现它。这意味着您可以尝试执行某些代码,如果失败,您可以执行其他操作。您还可以指定哪个错误将触发第二段代码。这是一个python示例:

try:
    #do something here
except IOError, e:
    #in the event of an IO error, do this, e is a variable you can choose to pass in that gives details about the error
except SystemExit:
    #another python exception
finally:
    #it is possible that html also supports a finally. Basically, no matter if it executes the try or one of the exception handlers, it will finish by doing this no matter what.