【问题标题】:How to find "invoke_user_function" function for Python 3.8 runtime for Google Cloud Functions如何为 Google Cloud Functions 的 Python 3.8 运行时找到“invoke_user_function”函数
【发布时间】:2020-08-17 07:53:25
【问题描述】:

我目前正在从事一个个人项目,该项目需要我访问 Google Cloud Functions 的运行时参数。谷歌云函数 目前支持 2 个运行时,Python 3.7 和 Python 3.8。

我为 Python 3.7 运行时编写了以下代码:-

from google.cloud import functions as func

def hello_world(request):
    print(dir(func))
    print(dir(func.worker_v1))
    print(dir(func.worker_v1.FunctionHandler))

我得到以下输出:-

[
'_USE_WORKER_V2', '_USE_WORKER_V2_VAR', '__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__',
'os', 'worker_v1', 'worker_v2'
]

[
'FunctionHandler', 'HTTPException', 'LogBuffer', 'LogInfo', 'LoggingWorker', 'NoLoggingWSGIRequestHandler', 'TEMPLATE_FOLDER', 'WSGIRequestHandler', 'WSGIServer',
'_CODE_LOCATION', '_CONTAINER_LOGGING_ENABLED', '_CRASH', '_ENTRY_POINT', '_EXECUTE_PREFIX', '_Event', '_FUNCTION_NAME', '_FUNCTION_STATUS_HEADER_FIELD',
'_FUNCTION_TRIGGER_TYPE', '_FUNCTION_VERSION', '_GOOGLE_CLOUD_DEBUG_ENABLED', '_GOOGLE_CLOUD_TRACE_ENABLED', '_GOOGLE_CONTAINER_LOGGING_ENABLED', '_HTTP_TRIGGER',
'_IPv6Server', '_LOAD_ERROR', '_MAX_LOG_BATCH_ENTRIES', '_MAX_LOG_BATCH_LENGTH', '_MAX_LOG_LENGTH', '_SUPERVISOR_HOSTNAME', '_SUPERVISOR_INTERNAL_PORT',
'_SUPERVISOR_LOG_PERIOD_SEC', '_SUPERVISOR_LOG_TIMEOUT_SEC', '_TRACER', '_TRACE_ENABLED', '_URL_PATTERN', '_WORKER_PORT',
'__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_adjust_response_with_trace_header', '_adjust_trace_span',
'_adjust_user_request', '_datetime_now_utc', '_ensure_leading_slash', '_function_handler', '_remove_prefix', '_url_with_slash_after_hostname',
'app', 'asyncio', 'check_or_load_user_function', 'check_worker', 'collections', 'datetime', 'event_context', 'flask', 'io', 'json', 'logging', 'main', 'make_server',
'os', 'post_to_supervisor', 'queue', 're', 'redirect_stdout_and_stderr', 'requests', 'routing', 'run_background_function', 'setup_logging', 'signal', 'socket', 'sys',
'threading', 'time', 'traceback', 'try_enable_tracing', 'util'
]

[
'__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__',
'__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__',
'__str__', '__subclasshook__', '__weakref__', '_user_function',
'flush', 'has_user_function', 'invoke_user_function', 'load_user_function', 'log_user_error'
]

正如您在上面看到的,有一个“invoke_user_function”函数,这正是我需要的函数。

现在,我得到了 Python3.7 运行时环境的这些结果,但对于 Python 3.8,我没有得到这些结果。

对于 Python 3.8 运行时,我编写了以下代码:-

from google.cloud import functions as func

def hello_world(request):
    print(dir(func))
    print(dir(func.context))
    return "string"

我得到以下输出:-


['Context', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__']

在 Python3.8 运行时,我无法获得我的项目所需的“invoke_user_function”函数。

重要问题:有没有人遇到过这种情况并且知道在 Python3.8 的情况下在哪里可以找到它?

【问题讨论】:

    标签: google-cloud-functions python-3.7 python-3.8


    【解决方案1】:

    我已经在我这边复制了这个,所以我可以确认它不起作用。但是Python 3.8 runtime 处于 Beta 阶段,所以还没有准备好。

    如果你需要这个,你可以尝试去支持页面部分Beta tester group 这应该是提出这个问题的更好地方。

    【讨论】:

    • 谢谢。我想我需要去 Beta 测试组来解决这个问题。
    猜你喜欢
    • 2020-06-16
    • 2021-05-03
    • 2019-11-15
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 2023-03-28
    • 2020-01-07
    • 2019-07-11
    相关资源
    最近更新 更多