0

我一直在使用的命令是:

 pserve development.ini --reload

每次遇到 SQLAlchemy 的“IntegrityError”或其他错误时,
我都必须再次终止 pserve 键入命令以重新启动应用程序。

有没有一种方法可以在这样的异常视图中重新启动应用程序?

@view_config(context=Exception)
def error_view(exc, request):
    #restart the waitress or apache...
    return Response("Sorry there was an error, wait seconds, we will fix it soon.")
4

2 回答 2

2

Restarting your server is not a sensical response to an IntegrityError. This is something that is expected to happen and you need to handle it. Restarting the server really makes no sense in the context of anything other than development.

If you run into exceptions in development, fix the code and save the file and the --reload will automatically restart your server for you.

于 2013-07-12T07:32:51.503 回答
0

如果您必须在出现异常后重新启动应用程序(可能是因为在异常发生后没有任何效果),它建议您的请求尝试重新使用相同的事务 - 换句话说,您的应用程序配置不正确。

当 Pyramide 的脚手架生成时,您应该使用配置了 ZopeTransactionExtension 的会话。

如果您向我们展示一些代码,我们可能能够查明问题的确切原因。

于 2013-07-12T21:16:34.360 回答