0

我想要做的是检查启动事件的条件,如果发生执行,不要启动服务器或停止服务器。


@app.on_event("startup")
def startup_event():
    public_key = None

    try:
        with open(PUBLIC_KEY_FILE) as public_key_file:
            public_key = public_key_file.read()
    except Exception as f_error:
        logger.exception(f_error)

        # cancel the startup

有没有办法做到这一点?

4

1 回答 1

0

在启动函数中引发异常:


@app.on_event("startup")
def startup_event():
    public_key = None

    try:
        with open(PUBLIC_KEY_FILE) as public_key_file:
            public_key = public_key_file.read()
    except Exception as f_error:
        logger.exception(f_error)

        raise SomeException()
于 2021-05-05T19:48:42.983 回答