def exit(status, message=None):
    """
    Exit the python interpreter with the given status and an optional message.

    @param status: An exit status.
    @type status: L{int} or L{ValueConstant} from L{ExitStatus}.

    @param message: An options message to print.
    @type status: L{str}
    """
    if isinstance(status, ValueConstant):
        code = status.value
    else:
        code = int(status)

    if message:
        if code == 0:
            out = stdout
        else:
            out = stderr
        out.write(message)
        out.write("\n")

    sysexit(code)

    Exit the python interpreter with the given status and an optional message.

    @param status: An exit status.
    @type status: L{int} or L{ValueConstant} from L{ExitStatus}.

    @param message: An options message to print.
    @type status: L{str}
    
stackoverflow/venv/lib/python3.6/site-packages/twisted/application/runner/_exit.py