简体   繁体   English

sys.exit() GCP 云 Function

[英]sys.exit() GCP Cloud Function

Have written GCP Cloud Function in Python 3.7.在Python 3.7写了GCP Cloud Function。 While executing, sys.exit() I'm getting 'A server error occurred...'.在执行sys.exit()时,我收到“发生服务器错误...”。 I need to exit out of the function and have written following code.我需要退出 function 并编写了以下代码。

import sys 
if str(strEnabled) == 'True':
        printOperation = "Operation: Enabling of user" 
else:
        sys.exit() #Exit From the Program

Please suggest, what I'm missing here.请提出建议,我在这里缺少什么。

Use return instead of sys.exit使用return而不是sys.exit

Copied from bigbounty 's comment复制自bigbounty评论

If you are calling a function from another function and needs to directly exit from the inner function without return you can use abort .如果你正在从另一个 function 调用一个 function 并且需要直接从内部 function 退出而不return你可以使用abort

abort will directly return the response and exit the program from the place you are calling it. abort将直接返回响应并从您调用它的地方退出程序。

import sys 
from flask import abort

if str(strEnabled) == 'True':
    printOperation = "Operation: Enabling of user" 
else:
    # abort(200) #return 200
    abort(500, description="Exit") #return 500

Note: cloud functions use flask module internally, so you need not install it separately.注意:云函数内部使用flask模块,不需要单独安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM